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

StrChrIW

関数
大文字小文字を区別せず最初の指定文字を検索する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

LPWSTR StrChrIW(
    LPCWSTR pszStart,
    WCHAR wMatch
);

パラメーター

名前方向
pszStartLPCWSTRin
wMatchWCHARin

戻り値の型: LPWSTR

各言語での呼び出し定義

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

LPWSTR StrChrIW(
    LPCWSTR pszStart,
    WCHAR wMatch
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr StrChrIW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszStart,   // LPCWSTR
    char wMatch   // WCHAR
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrChrIW(
    <MarshalAs(UnmanagedType.LPWStr)> pszStart As String,   ' LPCWSTR
    wMatch As Char   ' WCHAR
) As IntPtr
End Function
' pszStart : LPCWSTR
' wMatch : WCHAR
Declare PtrSafe Function StrChrIW Lib "shlwapi" ( _
    ByVal pszStart As LongPtr, _
    ByVal wMatch As Integer) 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

StrChrIW = ctypes.windll.shlwapi.StrChrIW
StrChrIW.restype = wintypes.LPWSTR
StrChrIW.argtypes = [
    wintypes.LPCWSTR,  # pszStart : LPCWSTR
    ctypes.c_wchar,  # wMatch : WCHAR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrChrIW = shlwapi.NewProc("StrChrIW")
)

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