StrRChrA
関数範囲内で最後に出現する指定文字を検索する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
LPSTR StrRChrA(
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 ヘッダーは StrRChr をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 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 // LPSTRfunction 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)。const std = @import("std");
extern "shlwapi" fn StrRChrA(
pszStart: [*c]const u8, // LPCSTR
pszEnd: [*c]const u8, // LPCSTR optional
wMatch: u16 // WORD
) callconv(std.os.windows.WINAPI) [*c]const u8;proc StrRChrA(
pszStart: cstring, # LPCSTR
pszEnd: cstring, # LPCSTR optional
wMatch: uint16 # WORD
): cstring {.importc: "StrRChrA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
const(char)* StrRChrA(
const(char)* pszStart, // LPCSTR
const(char)* pszEnd, // LPCSTR optional
ushort wMatch // WORD
);ccall((:StrRChrA, "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* StrRChrA(
const char* pszStart,
const char* pszEnd,
uint16_t wMatch);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.StrRChrA(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 StrRChrA = lib.func('__stdcall', 'StrRChrA', 'void *', ['str', 'str', 'uint16_t']);
// StrRChrA(pszStart, pszEnd, wMatch)
// pszStart : LPCSTR -> 'str'
// pszEnd : LPCSTR optional -> 'str'
// wMatch : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
StrRChrA: { parameters: ["buffer", "buffer", "u16"], result: "pointer" },
});
// lib.symbols.StrRChrA(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* StrRChrA(
const char* pszStart,
const char* pszEnd,
uint16_t wMatch);
C, "SHLWAPI.dll");
// $ffi->StrRChrA(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 StrRChrA(
String pszStart, // LPCSTR
String pszEnd, // LPCSTR optional
short wMatch // WORD
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun StrRChrA = StrRChrA(
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 StrRChrANative = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, Uint16);
typedef StrRChrADart = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>, int);
final StrRChrA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<StrRChrANative, StrRChrADart>('StrRChrA');
// pszStart : LPCSTR -> Pointer<Utf8>
// pszEnd : LPCSTR optional -> Pointer<Utf8>
// wMatch : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function StrRChrA(
pszStart: PAnsiChar; // LPCSTR
pszEnd: PAnsiChar; // LPCSTR optional
wMatch: Word // WORD
): PAnsiChar; stdcall;
external 'SHLWAPI.dll' name 'StrRChrA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "StrRChrA"
c_StrRChrA :: 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 strrchra =
foreign "StrRChrA"
(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 ("StrRChrA" str-rchr-a :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 $StrRChrA = Win32::API::More->new('SHLWAPI',
'LPSTR StrRChrA(LPCSTR pszStart, LPCSTR pszEnd, WORD wMatch)');
# my $ret = $StrRChrA->Call($pszStart, $pszEnd, $wMatch);
# pszStart : LPCSTR -> LPCSTR
# pszEnd : LPCSTR optional -> LPCSTR
# wMatch : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f StrRChrW (Unicode版) — 範囲内で最後に出現する指定文字を検索する。