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

StrRChrA

関数
範囲内で最後に出現する指定文字を検索する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

LPSTR StrRChrA(
    LPCSTR pszStart,
    LPCSTR pszEnd,   // optional
    WORD wMatch
);

パラメーター

名前方向
pszStartLPCSTRin
pszEndLPCSTRinoptional
wMatchWORDin

戻り値の型: LPSTR

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

LPSTR StrRChrA(
    LPCSTR pszStart,
    LPCSTR pszEnd,   // optional
    WORD wMatch
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr StrRChrA(
    [MarshalAs(UnmanagedType.LPStr)] string pszStart,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string pszEnd,   // LPCSTR optional
    ushort wMatch   // WORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function StrRChrA(
    <MarshalAs(UnmanagedType.LPStr)> pszStart As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> pszEnd As String,   ' LPCSTR optional
    wMatch As UShort   ' WORD
) As IntPtr
End Function
' pszStart : LPCSTR
' pszEnd : LPCSTR optional
' wMatch : WORD
Declare PtrSafe Function StrRChrA Lib "shlwapi" ( _
    ByVal pszStart As String, _
    ByVal pszEnd As String, _
    ByVal wMatch As Integer) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

StrRChrA = ctypes.windll.shlwapi.StrRChrA
StrRChrA.restype = wintypes.LPSTR
StrRChrA.argtypes = [
    wintypes.LPCSTR,  # pszStart : LPCSTR
    wintypes.LPCSTR,  # pszEnd : LPCSTR optional
    ctypes.c_ushort,  # wMatch : WORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
StrRChrA = Fiddle::Function.new(
  lib['StrRChrA'],
  [
    Fiddle::TYPE_VOIDP,  # pszStart : LPCSTR
    Fiddle::TYPE_VOIDP,  # pszEnd : LPCSTR optional
    -Fiddle::TYPE_SHORT,  # wMatch : WORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "shlwapi")]
extern "system" {
    fn StrRChrA(
        pszStart: *const u8,  // LPCSTR
        pszEnd: *const u8,  // LPCSTR optional
        wMatch: u16  // WORD
    ) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr StrRChrA([MarshalAs(UnmanagedType.LPStr)] string pszStart, [MarshalAs(UnmanagedType.LPStr)] string pszEnd, ushort wMatch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrRChrA' -Namespace Win32 -PassThru
# $api::StrRChrA(pszStart, pszEnd, wMatch)
#uselib "SHLWAPI.dll"
#func global StrRChrA "StrRChrA" sptr, sptr, sptr
; StrRChrA pszStart, pszEnd, wMatch   ; 戻り値は stat
; pszStart : LPCSTR -> "sptr"
; pszEnd : LPCSTR optional -> "sptr"
; wMatch : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global StrRChrA "StrRChrA" str, str, int
; res = StrRChrA(pszStart, pszEnd, wMatch)
; pszStart : LPCSTR -> "str"
; pszEnd : LPCSTR optional -> "str"
; wMatch : WORD -> "int"
; LPSTR StrRChrA(LPCSTR pszStart, LPCSTR pszEnd, WORD wMatch)
#uselib "SHLWAPI.dll"
#cfunc global StrRChrA "StrRChrA" str, str, int
; res = StrRChrA(pszStart, pszEnd, wMatch)
; pszStart : LPCSTR -> "str"
; pszEnd : LPCSTR optional -> "str"
; wMatch : WORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrRChrA = shlwapi.NewProc("StrRChrA")
)

// pszStart (LPCSTR), pszEnd (LPCSTR optional), wMatch (WORD)
r1, _, err := procStrRChrA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszStart))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszEnd))),
	uintptr(wMatch),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPSTR
function StrRChrA(
  pszStart: PAnsiChar;   // LPCSTR
  pszEnd: PAnsiChar;   // LPCSTR optional
  wMatch: Word   // WORD
): PAnsiChar; stdcall;
  external 'SHLWAPI.dll' name 'StrRChrA';
result := DllCall("SHLWAPI\StrRChrA"
    , "AStr", pszStart   ; LPCSTR
    , "AStr", pszEnd   ; LPCSTR optional
    , "UShort", wMatch   ; WORD
    , "Ptr")   ; return: LPSTR
●StrRChrA(pszStart, pszEnd, wMatch) = DLL("SHLWAPI.dll", "char* StrRChrA(char*, char*, int)")
# 呼び出し: StrRChrA(pszStart, pszEnd, wMatch)
# pszStart : LPCSTR -> "char*"
# pszEnd : LPCSTR optional -> "char*"
# wMatch : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。