StrRChrIA
関数大小文字無視で最後に出現する指定文字を検索する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
LPSTR StrRChrIA(
LPCSTR pszStart,
LPCSTR pszEnd, // optional
WORD wMatch
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszStart | LPCSTR | in | 検索対象となる null 終端文字列へのポインター。 |
| pszEnd | LPCSTR | inoptional | 検索範囲を定義する、ソース文字列内へのポインター。pszEnd が文字列内のある文字を指すように設定すると、検索はその直前の文字までで停止します。文字列全体を検索するには、pszEnd を NULL に設定します。 |
| wMatch | WORD | in | 検索する文字。 |
戻り値の型: LPSTR
公式ドキュメント
文字列から、指定した文字が最後に出現する位置を検索します。比較では大文字と小文字は区別されません。(ANSI)
戻り値
型: PTSTR
成功した場合は、文字列内でその文字が最後に出現する位置へのポインターを返します。見つからない場合は NULL を返します。
解説(Remarks)
この比較では、pszEnd が文字列の末尾を指していることを前提とします。
メモ
shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして StrRChrI を定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイル エラーや実行時エラーの原因となる場合があります。詳細については、「関数プロトタイプの規約」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
LPSTR StrRChrIA(
LPCSTR pszStart,
LPCSTR pszEnd, // optional
WORD wMatch
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr StrRChrIA(
[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 StrRChrIA(
<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 StrRChrIA 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
StrRChrIA = ctypes.windll.shlwapi.StrRChrIA
StrRChrIA.restype = wintypes.LPSTR
StrRChrIA.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')
StrRChrIA = Fiddle::Function.new(
lib['StrRChrIA'],
[
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 StrRChrIA(
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 StrRChrIA([MarshalAs(UnmanagedType.LPStr)] string pszStart, [MarshalAs(UnmanagedType.LPStr)] string pszEnd, ushort wMatch);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrRChrIA' -Namespace Win32 -PassThru
# $api::StrRChrIA(pszStart, pszEnd, wMatch)#uselib "SHLWAPI.dll"
#func global StrRChrIA "StrRChrIA" sptr, sptr, sptr
; StrRChrIA pszStart, pszEnd, wMatch ; 戻り値は stat
; pszStart : LPCSTR -> "sptr"
; pszEnd : LPCSTR optional -> "sptr"
; wMatch : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global StrRChrIA "StrRChrIA" str, str, int
; res = StrRChrIA(pszStart, pszEnd, wMatch)
; pszStart : LPCSTR -> "str"
; pszEnd : LPCSTR optional -> "str"
; wMatch : WORD -> "int"; LPSTR StrRChrIA(LPCSTR pszStart, LPCSTR pszEnd, WORD wMatch)
#uselib "SHLWAPI.dll"
#cfunc global StrRChrIA "StrRChrIA" str, str, int
; res = StrRChrIA(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")
procStrRChrIA = shlwapi.NewProc("StrRChrIA")
)
// pszStart (LPCSTR), pszEnd (LPCSTR optional), wMatch (WORD)
r1, _, err := procStrRChrIA.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 // LPSTRfunction StrRChrIA(
pszStart: PAnsiChar; // LPCSTR
pszEnd: PAnsiChar; // LPCSTR optional
wMatch: Word // WORD
): PAnsiChar; stdcall;
external 'SHLWAPI.dll' name 'StrRChrIA';result := DllCall("SHLWAPI\StrRChrIA"
, "AStr", pszStart ; LPCSTR
, "AStr", pszEnd ; LPCSTR optional
, "UShort", wMatch ; WORD
, "Ptr") ; return: LPSTR●StrRChrIA(pszStart, pszEnd, wMatch) = DLL("SHLWAPI.dll", "char* StrRChrIA(char*, char*, int)")
# 呼び出し: StrRChrIA(pszStart, pszEnd, wMatch)
# pszStart : LPCSTR -> "char*"
# pszEnd : LPCSTR optional -> "char*"
# wMatch : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn StrRChrIA(
pszStart: [*c]const u8, // LPCSTR
pszEnd: [*c]const u8, // LPCSTR optional
wMatch: u16 // WORD
) callconv(std.os.windows.WINAPI) [*c]const u8;proc StrRChrIA(
pszStart: cstring, # LPCSTR
pszEnd: cstring, # LPCSTR optional
wMatch: uint16 # WORD
): cstring {.importc: "StrRChrIA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
const(char)* StrRChrIA(
const(char)* pszStart, // LPCSTR
const(char)* pszEnd, // LPCSTR optional
ushort wMatch // WORD
);ccall((:StrRChrIA, "SHLWAPI.dll"), stdcall, Cstring,
(Cstring, Cstring, UInt16),
pszStart, pszEnd, wMatch)
# pszStart : LPCSTR -> Cstring
# pszEnd : LPCSTR optional -> Cstring
# wMatch : WORD -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
const char* StrRChrIA(
const char* pszStart,
const char* pszEnd,
uint16_t wMatch);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.StrRChrIA(pszStart, pszEnd, wMatch)
-- pszStart : LPCSTR
-- pszEnd : LPCSTR optional
-- wMatch : WORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const StrRChrIA = lib.func('__stdcall', 'StrRChrIA', 'void *', ['str', 'str', 'uint16_t']);
// StrRChrIA(pszStart, pszEnd, wMatch)
// pszStart : LPCSTR -> 'str'
// pszEnd : LPCSTR optional -> 'str'
// wMatch : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
StrRChrIA: { parameters: ["buffer", "buffer", "u16"], result: "pointer" },
});
// lib.symbols.StrRChrIA(pszStart, pszEnd, wMatch)
// pszStart : LPCSTR -> "buffer"
// pszEnd : LPCSTR optional -> "buffer"
// wMatch : WORD -> "u16"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const char* StrRChrIA(
const char* pszStart,
const char* pszEnd,
uint16_t wMatch);
C, "SHLWAPI.dll");
// $ffi->StrRChrIA(pszStart, pszEnd, wMatch);
// pszStart : LPCSTR
// pszEnd : LPCSTR optional
// wMatch : WORD
// 構造体/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.ASCII_OPTIONS);
Pointer StrRChrIA(
String pszStart, // LPCSTR
String pszEnd, // LPCSTR optional
short wMatch // WORD
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun StrRChrIA = StrRChrIA(
pszStart : UInt8*, # LPCSTR
pszEnd : UInt8*, # LPCSTR optional
wMatch : UInt16 # WORD
) : UInt8*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef StrRChrIANative = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, Uint16);
typedef StrRChrIADart = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int);
final StrRChrIA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<StrRChrIANative, StrRChrIADart>('StrRChrIA');
// pszStart : LPCSTR -> Pointer<Utf8>
// pszEnd : LPCSTR optional -> Pointer<Utf8>
// wMatch : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function StrRChrIA(
pszStart: PAnsiChar; // LPCSTR
pszEnd: PAnsiChar; // LPCSTR optional
wMatch: Word // WORD
): PAnsiChar; stdcall;
external 'SHLWAPI.dll' name 'StrRChrIA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "StrRChrIA"
c_StrRChrIA :: CString -> CString -> Word16 -> IO CString
-- pszStart : LPCSTR -> CString
-- pszEnd : LPCSTR optional -> CString
-- wMatch : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let strrchria =
foreign "StrRChrIA"
(string @-> string @-> uint16_t @-> returning string)
(* pszStart : LPCSTR -> string *)
(* pszEnd : LPCSTR optional -> string *)
(* wMatch : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("StrRChrIA" str-rchr-ia :convention :stdcall) :string
(psz-start :string) ; LPCSTR
(psz-end :string) ; LPCSTR optional
(w-match :uint16)) ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $StrRChrIA = Win32::API::More->new('SHLWAPI',
'LPSTR StrRChrIA(LPCSTR pszStart, LPCSTR pszEnd, WORD wMatch)');
# my $ret = $StrRChrIA->Call($pszStart, $pszEnd, $wMatch);
# pszStart : LPCSTR -> LPCSTR
# pszEnd : LPCSTR optional -> LPCSTR
# wMatch : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f StrRChrIW (Unicode版) — 大小文字無視で最後に出現する指定文字を検索する。