StrStrW
関数文字列内で最初に出現する部分文字列を検索する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
LPWSTR StrStrW(
LPCWSTR pszFirst,
LPCWSTR pszSrch
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszFirst | LPCWSTR | in |
| pszSrch | LPCWSTR | in |
戻り値の型: LPWSTR
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
LPWSTR StrStrW(
LPCWSTR pszFirst,
LPCWSTR pszSrch
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr StrStrW(
[MarshalAs(UnmanagedType.LPWStr)] string pszFirst, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszSrch // LPCWSTR
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrStrW(
<MarshalAs(UnmanagedType.LPWStr)> pszFirst As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszSrch As String ' LPCWSTR
) As IntPtr
End Function' pszFirst : LPCWSTR
' pszSrch : LPCWSTR
Declare PtrSafe Function StrStrW Lib "shlwapi" ( _
ByVal pszFirst As LongPtr, _
ByVal pszSrch As LongPtr) As LongPtr
' 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
StrStrW = ctypes.windll.shlwapi.StrStrW
StrStrW.restype = wintypes.LPWSTR
StrStrW.argtypes = [
wintypes.LPCWSTR, # pszFirst : LPCWSTR
wintypes.LPCWSTR, # pszSrch : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
StrStrW = Fiddle::Function.new(
lib['StrStrW'],
[
Fiddle::TYPE_VOIDP, # pszFirst : LPCWSTR
Fiddle::TYPE_VOIDP, # pszSrch : LPCWSTR
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn StrStrW(
pszFirst: *const u16, // LPCWSTR
pszSrch: *const u16 // LPCWSTR
) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr StrStrW([MarshalAs(UnmanagedType.LPWStr)] string pszFirst, [MarshalAs(UnmanagedType.LPWStr)] string pszSrch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrStrW' -Namespace Win32 -PassThru
# $api::StrStrW(pszFirst, pszSrch)#uselib "SHLWAPI.dll"
#func global StrStrW "StrStrW" wptr, wptr
; StrStrW pszFirst, pszSrch ; 戻り値は stat
; pszFirst : LPCWSTR -> "wptr"
; pszSrch : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global StrStrW "StrStrW" wstr, wstr
; res = StrStrW(pszFirst, pszSrch)
; pszFirst : LPCWSTR -> "wstr"
; pszSrch : LPCWSTR -> "wstr"; LPWSTR StrStrW(LPCWSTR pszFirst, LPCWSTR pszSrch)
#uselib "SHLWAPI.dll"
#cfunc global StrStrW "StrStrW" wstr, wstr
; res = StrStrW(pszFirst, pszSrch)
; pszFirst : LPCWSTR -> "wstr"
; pszSrch : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procStrStrW = shlwapi.NewProc("StrStrW")
)
// pszFirst (LPCWSTR), pszSrch (LPCWSTR)
r1, _, err := procStrStrW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFirst))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSrch))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPWSTRfunction StrStrW(
pszFirst: PWideChar; // LPCWSTR
pszSrch: PWideChar // LPCWSTR
): PWideChar; stdcall;
external 'SHLWAPI.dll' name 'StrStrW';result := DllCall("SHLWAPI\StrStrW"
, "WStr", pszFirst ; LPCWSTR
, "WStr", pszSrch ; LPCWSTR
, "Ptr") ; return: LPWSTR●StrStrW(pszFirst, pszSrch) = DLL("SHLWAPI.dll", "char* StrStrW(char*, char*)")
# 呼び出し: StrStrW(pszFirst, pszSrch)
# pszFirst : LPCWSTR -> "char*"
# pszSrch : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。