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