Win32 API 日本語リファレンス
ホームUI.Shell › StrSpnW

StrSpnW

関数
指定文字集合のみで構成される先頭部分の長さを取得する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

INT StrSpnW(
    LPCWSTR psz,
    LPCWSTR pszSet
);

パラメーター

名前方向
pszLPCWSTRin
pszSetLPCWSTRin

戻り値の型: INT

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

INT StrSpnW(
    LPCWSTR psz,
    LPCWSTR pszSet
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int StrSpnW(
    [MarshalAs(UnmanagedType.LPWStr)] string psz,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszSet   // LPCWSTR
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrSpnW(
    <MarshalAs(UnmanagedType.LPWStr)> psz As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszSet As String   ' LPCWSTR
) As Integer
End Function
' psz : LPCWSTR
' pszSet : LPCWSTR
Declare PtrSafe Function StrSpnW Lib "shlwapi" ( _
    ByVal psz As LongPtr, _
    ByVal pszSet As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

StrSpnW = ctypes.windll.shlwapi.StrSpnW
StrSpnW.restype = ctypes.c_int
StrSpnW.argtypes = [
    wintypes.LPCWSTR,  # psz : LPCWSTR
    wintypes.LPCWSTR,  # pszSet : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
StrSpnW = Fiddle::Function.new(
  lib['StrSpnW'],
  [
    Fiddle::TYPE_VOIDP,  # psz : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszSet : LPCWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn StrSpnW(
        psz: *const u16,  // LPCWSTR
        pszSet: *const u16  // LPCWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern int StrSpnW([MarshalAs(UnmanagedType.LPWStr)] string psz, [MarshalAs(UnmanagedType.LPWStr)] string pszSet);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrSpnW' -Namespace Win32 -PassThru
# $api::StrSpnW(psz, pszSet)
#uselib "SHLWAPI.dll"
#func global StrSpnW "StrSpnW" wptr, wptr
; StrSpnW psz, pszSet   ; 戻り値は stat
; psz : LPCWSTR -> "wptr"
; pszSet : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global StrSpnW "StrSpnW" wstr, wstr
; res = StrSpnW(psz, pszSet)
; psz : LPCWSTR -> "wstr"
; pszSet : LPCWSTR -> "wstr"
; INT StrSpnW(LPCWSTR psz, LPCWSTR pszSet)
#uselib "SHLWAPI.dll"
#cfunc global StrSpnW "StrSpnW" wstr, wstr
; res = StrSpnW(psz, pszSet)
; psz : LPCWSTR -> "wstr"
; pszSet : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrSpnW = shlwapi.NewProc("StrSpnW")
)

// psz (LPCWSTR), pszSet (LPCWSTR)
r1, _, err := procStrSpnW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSet))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function StrSpnW(
  psz: PWideChar;   // LPCWSTR
  pszSet: PWideChar   // LPCWSTR
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'StrSpnW';
result := DllCall("SHLWAPI\StrSpnW"
    , "WStr", psz   ; LPCWSTR
    , "WStr", pszSet   ; LPCWSTR
    , "Int")   ; return: INT
●StrSpnW(psz, pszSet) = DLL("SHLWAPI.dll", "int StrSpnW(char*, char*)")
# 呼び出し: StrSpnW(psz, pszSet)
# psz : LPCWSTR -> "char*"
# pszSet : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。