Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › SymMatchStringW

SymMatchStringW

関数
文字列がワイルドカード式に一致するか判定する。
DLLdbghelp.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL SymMatchStringW(
    LPCWSTR string,
    LPCWSTR expression,
    BOOL fCase
);

パラメーター

名前方向説明
stringLPCWSTRinexpression パラメーターと比較する、シンボル名などの文字列。
expressionLPCWSTRinstring パラメーターと比較するワイルドカード式。ワイルドカード式では * および ? 文字を使用できます。* は任意の文字列に一致し、? は任意の 1 文字に一致します。
fCaseBOOLin比較で大文字と小文字を区別するかどうかを示す変数。

戻り値の型: BOOL

公式ドキュメント

SymMatchStringW (Unicode) 関数は、指定した文字列を指定したワイルドカード式と比較します。

戻り値

関数が成功した場合、戻り値は TRUE です。

関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを避けるには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。

メモ

dbghelp.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SymMatchString を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が発生する可能性があります。詳細については、関数プロトタイプの規則を参照してください。

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

各言語での呼び出し定義

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

BOOL SymMatchStringW(
    LPCWSTR string,
    LPCWSTR expression,
    BOOL fCase
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SymMatchStringW(
    [MarshalAs(UnmanagedType.LPWStr)] string string,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string expression,   // LPCWSTR
    bool fCase   // BOOL
);
<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymMatchStringW(
    <MarshalAs(UnmanagedType.LPWStr)> [string] As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> expression As String,   ' LPCWSTR
    fCase As Boolean   ' BOOL
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' string : LPCWSTR
' expression : LPCWSTR
' fCase : BOOL
Declare PtrSafe Function SymMatchStringW Lib "dbghelp" ( _
    ByVal string As LongPtr, _
    ByVal expression As LongPtr, _
    ByVal fCase As Long) As Long
' 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

SymMatchStringW = ctypes.windll.dbghelp.SymMatchStringW
SymMatchStringW.restype = wintypes.BOOL
SymMatchStringW.argtypes = [
    wintypes.LPCWSTR,  # string : LPCWSTR
    wintypes.LPCWSTR,  # expression : LPCWSTR
    wintypes.BOOL,  # fCase : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
SymMatchStringW = Fiddle::Function.new(
  lib['SymMatchStringW'],
  [
    Fiddle::TYPE_VOIDP,  # string : LPCWSTR
    Fiddle::TYPE_VOIDP,  # expression : LPCWSTR
    Fiddle::TYPE_INT,  # fCase : BOOL
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "dbghelp")]
extern "system" {
    fn SymMatchStringW(
        string: *const u16,  // LPCWSTR
        expression: *const u16,  // LPCWSTR
        fCase: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SymMatchStringW([MarshalAs(UnmanagedType.LPWStr)] string string, [MarshalAs(UnmanagedType.LPWStr)] string expression, bool fCase);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymMatchStringW' -Namespace Win32 -PassThru
# $api::SymMatchStringW(string, expression, fCase)
#uselib "dbghelp.dll"
#func global SymMatchStringW "SymMatchStringW" wptr, wptr, wptr
; SymMatchStringW string, expression, fCase   ; 戻り値は stat
; string : LPCWSTR -> "wptr"
; expression : LPCWSTR -> "wptr"
; fCase : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "dbghelp.dll"
#cfunc global SymMatchStringW "SymMatchStringW" wstr, wstr, int
; res = SymMatchStringW(string, expression, fCase)
; string : LPCWSTR -> "wstr"
; expression : LPCWSTR -> "wstr"
; fCase : BOOL -> "int"
; BOOL SymMatchStringW(LPCWSTR string, LPCWSTR expression, BOOL fCase)
#uselib "dbghelp.dll"
#cfunc global SymMatchStringW "SymMatchStringW" wstr, wstr, int
; res = SymMatchStringW(string, expression, fCase)
; string : LPCWSTR -> "wstr"
; expression : LPCWSTR -> "wstr"
; fCase : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procSymMatchStringW = dbghelp.NewProc("SymMatchStringW")
)

// string (LPCWSTR), expression (LPCWSTR), fCase (BOOL)
r1, _, err := procSymMatchStringW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(string))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(expression))),
	uintptr(fCase),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SymMatchStringW(
  string: PWideChar;   // LPCWSTR
  expression: PWideChar;   // LPCWSTR
  fCase: BOOL   // BOOL
): BOOL; stdcall;
  external 'dbghelp.dll' name 'SymMatchStringW';
result := DllCall("dbghelp\SymMatchStringW"
    , "WStr", string   ; LPCWSTR
    , "WStr", expression   ; LPCWSTR
    , "Int", fCase   ; BOOL
    , "Int")   ; return: BOOL
●SymMatchStringW(string, expression, fCase) = DLL("dbghelp.dll", "bool SymMatchStringW(char*, char*, bool)")
# 呼び出し: SymMatchStringW(string, expression, fCase)
# string : LPCWSTR -> "char*"
# expression : LPCWSTR -> "char*"
# fCase : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "dbghelp" fn SymMatchStringW(
    string: [*c]const u16, // LPCWSTR
    expression: [*c]const u16, // LPCWSTR
    fCase: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SymMatchStringW(
    string: WideCString,  # LPCWSTR
    expression: WideCString,  # LPCWSTR
    fCase: int32  # BOOL
): int32 {.importc: "SymMatchStringW", stdcall, dynlib: "dbghelp.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "dbghelp");
extern(Windows)
int SymMatchStringW(
    const(wchar)* string,   // LPCWSTR
    const(wchar)* expression,   // LPCWSTR
    int fCase   // BOOL
);
ccall((:SymMatchStringW, "dbghelp.dll"), stdcall, Int32,
      (Cwstring, Cwstring, Int32),
      string, expression, fCase)
# string : LPCWSTR -> Cwstring
# expression : LPCWSTR -> Cwstring
# fCase : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SymMatchStringW(
    const uint16_t* string,
    const uint16_t* expression,
    int32_t fCase);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.SymMatchStringW(string, expression, fCase)
-- string : LPCWSTR
-- expression : LPCWSTR
-- fCase : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const SymMatchStringW = lib.func('__stdcall', 'SymMatchStringW', 'int32_t', ['str16', 'str16', 'int32_t']);
// SymMatchStringW(string, expression, fCase)
// string : LPCWSTR -> 'str16'
// expression : LPCWSTR -> 'str16'
// fCase : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dbghelp.dll", {
  SymMatchStringW: { parameters: ["buffer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.SymMatchStringW(string, expression, fCase)
// string : LPCWSTR -> "buffer"
// expression : LPCWSTR -> "buffer"
// fCase : BOOL -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SymMatchStringW(
    const uint16_t* string,
    const uint16_t* expression,
    int32_t fCase);
C, "dbghelp.dll");
// $ffi->SymMatchStringW(string, expression, fCase);
// string : LPCWSTR
// expression : LPCWSTR
// fCase : BOOL
// 構造体/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 Dbghelp extends StdCallLibrary {
    Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class, W32APIOptions.UNICODE_OPTIONS);
    boolean SymMatchStringW(
        WString string,   // LPCWSTR
        WString expression,   // LPCWSTR
        boolean fCase   // BOOL
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("dbghelp")]
lib Libdbghelp
  fun SymMatchStringW = SymMatchStringW(
    string : UInt16*,   # LPCWSTR
    expression : UInt16*,   # LPCWSTR
    fCase : Int32   # BOOL
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SymMatchStringWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef SymMatchStringWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int);
final SymMatchStringW = DynamicLibrary.open('dbghelp.dll')
    .lookupFunction<SymMatchStringWNative, SymMatchStringWDart>('SymMatchStringW');
// string : LPCWSTR -> Pointer<Utf16>
// expression : LPCWSTR -> Pointer<Utf16>
// fCase : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SymMatchStringW(
  string: PWideChar;   // LPCWSTR
  expression: PWideChar;   // LPCWSTR
  fCase: BOOL   // BOOL
): BOOL; stdcall;
  external 'dbghelp.dll' name 'SymMatchStringW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SymMatchStringW"
  c_SymMatchStringW :: CWString -> CWString -> CInt -> IO CInt
-- string : LPCWSTR -> CWString
-- expression : LPCWSTR -> CWString
-- fCase : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let symmatchstringw =
  foreign "SymMatchStringW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* string : LPCWSTR -> (ptr uint16_t) *)
(* expression : LPCWSTR -> (ptr uint16_t) *)
(* fCase : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)

(cffi:defcfun ("SymMatchStringW" sym-match-string-w :convention :stdcall) :int32
  (string (:string :encoding :utf-16le))   ; LPCWSTR
  (expression (:string :encoding :utf-16le))   ; LPCWSTR
  (f-case :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SymMatchStringW = Win32::API::More->new('dbghelp',
    'BOOL SymMatchStringW(LPCWSTR string, LPCWSTR expression, BOOL fCase)');
# my $ret = $SymMatchStringW->Call($string, $expression, $fCase);
# string : LPCWSTR -> LPCWSTR
# expression : LPCWSTR -> LPCWSTR
# fCase : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い