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

StrRChrIW

関数
大小文字無視で最後に出現する指定文字を検索する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

LPWSTR StrRChrIW(
    LPCWSTR pszStart,
    LPCWSTR pszEnd,   // optional
    WCHAR wMatch
);

パラメーター

名前方向説明
pszStartLPCWSTRin検索対象となる、null で終わる文字列へのポインターです。
pszEndLPCWSTRinoptional検索範囲を定義する、元の文字列内へのポインターです。pszEnd が文字列内のある文字を指すように設定すると、検索はその直前の文字で停止します。文字列全体を検索するには pszEndNULL に設定します。
wMatchWCHARin検索する文字です。

戻り値の型: LPWSTR

公式ドキュメント

文字列内で指定した文字が最後に出現する位置を検索します。比較では大文字と小文字を区別しません。(Unicode)

戻り値

型: PTSTR

成功した場合は、文字列内でその文字が最後に出現する位置へのポインターを返します。見つからない場合は NULL を返します。

解説(Remarks)

この比較では、pszEnd が文字列の末尾を指しているものと想定されます。

メモ

shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして StrRChrI を定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーまたは実行時エラーの原因となる場合があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

LPWSTR StrRChrIW(
    LPCWSTR pszStart,
    LPCWSTR pszEnd,   // optional
    WCHAR wMatch
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr StrRChrIW(
    [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 StrRChrIW(
    <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 StrRChrIW 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

StrRChrIW = ctypes.windll.shlwapi.StrRChrIW
StrRChrIW.restype = wintypes.LPWSTR
StrRChrIW.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')
StrRChrIW = Fiddle::Function.new(
  lib['StrRChrIW'],
  [
    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 StrRChrIW(
        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 StrRChrIW([MarshalAs(UnmanagedType.LPWStr)] string pszStart, [MarshalAs(UnmanagedType.LPWStr)] string pszEnd, char wMatch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrRChrIW' -Namespace Win32 -PassThru
# $api::StrRChrIW(pszStart, pszEnd, wMatch)
#uselib "SHLWAPI.dll"
#func global StrRChrIW "StrRChrIW" wptr, wptr, wptr
; StrRChrIW pszStart, pszEnd, wMatch   ; 戻り値は stat
; pszStart : LPCWSTR -> "wptr"
; pszEnd : LPCWSTR optional -> "wptr"
; wMatch : WCHAR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global StrRChrIW "StrRChrIW" wstr, wstr, int
; res = StrRChrIW(pszStart, pszEnd, wMatch)
; pszStart : LPCWSTR -> "wstr"
; pszEnd : LPCWSTR optional -> "wstr"
; wMatch : WCHAR -> "int"
; LPWSTR StrRChrIW(LPCWSTR pszStart, LPCWSTR pszEnd, WCHAR wMatch)
#uselib "SHLWAPI.dll"
#cfunc global StrRChrIW "StrRChrIW" wstr, wstr, int
; res = StrRChrIW(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")
	procStrRChrIW = shlwapi.NewProc("StrRChrIW")
)

// pszStart (LPCWSTR), pszEnd (LPCWSTR optional), wMatch (WCHAR)
r1, _, err := procStrRChrIW.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   // LPWSTR
function StrRChrIW(
  pszStart: PWideChar;   // LPCWSTR
  pszEnd: PWideChar;   // LPCWSTR optional
  wMatch: WideChar   // WCHAR
): PWideChar; stdcall;
  external 'SHLWAPI.dll' name 'StrRChrIW';
result := DllCall("SHLWAPI\StrRChrIW"
    , "WStr", pszStart   ; LPCWSTR
    , "WStr", pszEnd   ; LPCWSTR optional
    , "Short", wMatch   ; WCHAR
    , "Ptr")   ; return: LPWSTR
●StrRChrIW(pszStart, pszEnd, wMatch) = DLL("SHLWAPI.dll", "char* StrRChrIW(char*, char*, int)")
# 呼び出し: StrRChrIW(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 版の利用を推奨。
const std = @import("std");

extern "shlwapi" fn StrRChrIW(
    pszStart: [*c]const u16, // LPCWSTR
    pszEnd: [*c]const u16, // LPCWSTR optional
    wMatch: u16 // WCHAR
) callconv(std.os.windows.WINAPI) [*c]const u16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc StrRChrIW(
    pszStart: WideCString,  # LPCWSTR
    pszEnd: WideCString,  # LPCWSTR optional
    wMatch: uint16  # WCHAR
): WideCString {.importc: "StrRChrIW", stdcall, dynlib: "SHLWAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "shlwapi");
extern(Windows)
const(wchar)* StrRChrIW(
    const(wchar)* pszStart,   // LPCWSTR
    const(wchar)* pszEnd,   // LPCWSTR optional
    wchar wMatch   // WCHAR
);
ccall((:StrRChrIW, "SHLWAPI.dll"), stdcall, Cwstring,
      (Cwstring, Cwstring, UInt16),
      pszStart, pszEnd, wMatch)
# pszStart : LPCWSTR -> Cwstring
# pszEnd : LPCWSTR optional -> Cwstring
# wMatch : WCHAR -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
const uint16_t* StrRChrIW(
    const uint16_t* pszStart,
    const uint16_t* pszEnd,
    uint16_t wMatch);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.StrRChrIW(pszStart, pszEnd, wMatch)
-- pszStart : LPCWSTR
-- pszEnd : LPCWSTR optional
-- wMatch : WCHAR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const StrRChrIW = lib.func('__stdcall', 'StrRChrIW', 'void *', ['str16', 'str16', 'uint16_t']);
// StrRChrIW(pszStart, pszEnd, wMatch)
// pszStart : LPCWSTR -> 'str16'
// pszEnd : LPCWSTR optional -> 'str16'
// wMatch : WCHAR -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHLWAPI.dll", {
  StrRChrIW: { parameters: ["buffer", "buffer", "u16"], result: "pointer" },
});
// lib.symbols.StrRChrIW(pszStart, pszEnd, wMatch)
// pszStart : LPCWSTR -> "buffer"
// pszEnd : LPCWSTR optional -> "buffer"
// wMatch : WCHAR -> "u16"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
const uint16_t* StrRChrIW(
    const uint16_t* pszStart,
    const uint16_t* pszEnd,
    uint16_t wMatch);
C, "SHLWAPI.dll");
// $ffi->StrRChrIW(pszStart, pszEnd, wMatch);
// pszStart : LPCWSTR
// pszEnd : LPCWSTR optional
// wMatch : WCHAR
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Shlwapi extends StdCallLibrary {
    Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.UNICODE_OPTIONS);
    Pointer StrRChrIW(
        WString pszStart,   // LPCWSTR
        WString pszEnd,   // LPCWSTR optional
        char wMatch   // WCHAR
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("shlwapi")]
lib LibSHLWAPI
  fun StrRChrIW = StrRChrIW(
    pszStart : UInt16*,   # LPCWSTR
    pszEnd : UInt16*,   # LPCWSTR optional
    wMatch : UInt16   # WCHAR
  ) : UInt16*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef StrRChrIWNative = Pointer<Utf16> Function(Pointer<Utf16>, Pointer<Utf16>, Uint16);
typedef StrRChrIWDart = Pointer<Utf16> Function(Pointer<Utf16>, Pointer<Utf16>, int);
final StrRChrIW = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<StrRChrIWNative, StrRChrIWDart>('StrRChrIW');
// pszStart : LPCWSTR -> Pointer<Utf16>
// pszEnd : LPCWSTR optional -> Pointer<Utf16>
// wMatch : WCHAR -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function StrRChrIW(
  pszStart: PWideChar;   // LPCWSTR
  pszEnd: PWideChar;   // LPCWSTR optional
  wMatch: WideChar   // WCHAR
): PWideChar; stdcall;
  external 'SHLWAPI.dll' name 'StrRChrIW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "StrRChrIW"
  c_StrRChrIW :: CWString -> CWString -> Word16 -> IO CWString
-- pszStart : LPCWSTR -> CWString
-- pszEnd : LPCWSTR optional -> CWString
-- wMatch : WCHAR -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let strrchriw =
  foreign "StrRChrIW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> uint16_t @-> returning (ptr uint16_t))
(* pszStart : LPCWSTR -> (ptr uint16_t) *)
(* pszEnd : LPCWSTR optional -> (ptr uint16_t) *)
(* wMatch : WCHAR -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("StrRChrIW" str-rchr-iw :convention :stdcall) (:string :encoding :utf-16le)
  (psz-start (:string :encoding :utf-16le))   ; LPCWSTR
  (psz-end (:string :encoding :utf-16le))   ; LPCWSTR optional
  (w-match :uint16))   ; WCHAR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $StrRChrIW = Win32::API::More->new('SHLWAPI',
    'LPWSTR StrRChrIW(LPCWSTR pszStart, LPCWSTR pszEnd, WORD wMatch)');
# my $ret = $StrRChrIW->Call($pszStart, $pszEnd, $wMatch);
# pszStart : LPCWSTR -> LPCWSTR
# pszEnd : LPCWSTR optional -> LPCWSTR
# wMatch : WCHAR -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い