ホーム › System.Diagnostics.Debug › SymMatchFileNameW
SymMatchFileNameW
関数ファイル名がパターンに一致するか照合する(Unicode版)。
シグネチャ
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SymMatchFileNameW(
LPCWSTR FileName,
LPCWSTR Match,
LPWSTR* FileNameStop, // optional
LPWSTR* MatchStop // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCWSTR | in | Match パラメーターと比較されるファイル名です。 |
| Match | LPCWSTR | in | FileName パラメーターと比較される文字列です。 |
| FileNameStop | LPWSTR* | outoptional | FileName 内で照合が停止した位置へのポインターを受け取る文字列バッファーへのポインターです。完全に一致した場合、この値は FileName の 1 文字前になることがあります。この値は NULL でもかまいません。 |
| MatchStop | LPWSTR* | outoptional | Match 内で照合が停止した位置へのポインターを受け取る文字列バッファーへのポインターです。完全に一致した場合、この値は Match の 1 文字前になることがあります。この値は NULL でもかまいません。 |
戻り値の型: BOOL
公式ドキュメント
SymMatchFileNameW (Unicode) 関数は、文字列をファイル名およびパスと比較します。
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
照合文字列は完全なファイル名の接尾辞になり得るため、この関数を使用して単純なファイル名を完全修飾ファイル名と照合できます。
照合は両方の文字列の末尾から開始し、後方に向かって進みます。照合は大文字と小文字を区別せず、円記号 (\) とスラッシュ (/) を同一視します。
この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
この関数の Unicode バージョンを呼び出すには、DBGHELP_TRANSLATE_TCHAR を定義します。
メモ
dbghelp.h ヘッダーは、SymMatchFileName を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI バージョンまたは Unicode バージョンを自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SymMatchFileNameW(
LPCWSTR FileName,
LPCWSTR Match,
LPWSTR* FileNameStop, // optional
LPWSTR* MatchStop // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SymMatchFileNameW(
[MarshalAs(UnmanagedType.LPWStr)] string FileName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string Match, // LPCWSTR
IntPtr FileNameStop, // LPWSTR* optional, out
IntPtr MatchStop // LPWSTR* optional, out
);<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymMatchFileNameW(
<MarshalAs(UnmanagedType.LPWStr)> FileName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> Match As String, ' LPCWSTR
FileNameStop As IntPtr, ' LPWSTR* optional, out
MatchStop As IntPtr ' LPWSTR* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' FileName : LPCWSTR
' Match : LPCWSTR
' FileNameStop : LPWSTR* optional, out
' MatchStop : LPWSTR* optional, out
Declare PtrSafe Function SymMatchFileNameW Lib "dbghelp" ( _
ByVal FileName As LongPtr, _
ByVal Match As LongPtr, _
ByVal FileNameStop As LongPtr, _
ByVal MatchStop As LongPtr) 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
SymMatchFileNameW = ctypes.windll.dbghelp.SymMatchFileNameW
SymMatchFileNameW.restype = wintypes.BOOL
SymMatchFileNameW.argtypes = [
wintypes.LPCWSTR, # FileName : LPCWSTR
wintypes.LPCWSTR, # Match : LPCWSTR
ctypes.c_void_p, # FileNameStop : LPWSTR* optional, out
ctypes.c_void_p, # MatchStop : LPWSTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
SymMatchFileNameW = Fiddle::Function.new(
lib['SymMatchFileNameW'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCWSTR
Fiddle::TYPE_VOIDP, # Match : LPCWSTR
Fiddle::TYPE_VOIDP, # FileNameStop : LPWSTR* optional, out
Fiddle::TYPE_VOIDP, # MatchStop : LPWSTR* optional, out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "dbghelp")]
extern "system" {
fn SymMatchFileNameW(
FileName: *const u16, // LPCWSTR
Match: *const u16, // LPCWSTR
FileNameStop: *mut *mut u16, // LPWSTR* optional, out
MatchStop: *mut *mut u16 // LPWSTR* optional, out
) -> 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 SymMatchFileNameW([MarshalAs(UnmanagedType.LPWStr)] string FileName, [MarshalAs(UnmanagedType.LPWStr)] string Match, IntPtr FileNameStop, IntPtr MatchStop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymMatchFileNameW' -Namespace Win32 -PassThru
# $api::SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop)#uselib "dbghelp.dll"
#func global SymMatchFileNameW "SymMatchFileNameW" wptr, wptr, wptr, wptr
; SymMatchFileNameW FileName, Match, varptr(FileNameStop), varptr(MatchStop) ; 戻り値は stat
; FileName : LPCWSTR -> "wptr"
; Match : LPCWSTR -> "wptr"
; FileNameStop : LPWSTR* optional, out -> "wptr"
; MatchStop : LPWSTR* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "dbghelp.dll" #cfunc global SymMatchFileNameW "SymMatchFileNameW" wstr, wstr, var, var ; res = SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop) ; FileName : LPCWSTR -> "wstr" ; Match : LPCWSTR -> "wstr" ; FileNameStop : LPWSTR* optional, out -> "var" ; MatchStop : LPWSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dbghelp.dll" #cfunc global SymMatchFileNameW "SymMatchFileNameW" wstr, wstr, sptr, sptr ; res = SymMatchFileNameW(FileName, Match, varptr(FileNameStop), varptr(MatchStop)) ; FileName : LPCWSTR -> "wstr" ; Match : LPCWSTR -> "wstr" ; FileNameStop : LPWSTR* optional, out -> "sptr" ; MatchStop : LPWSTR* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SymMatchFileNameW(LPCWSTR FileName, LPCWSTR Match, LPWSTR* FileNameStop, LPWSTR* MatchStop) #uselib "dbghelp.dll" #cfunc global SymMatchFileNameW "SymMatchFileNameW" wstr, wstr, var, var ; res = SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop) ; FileName : LPCWSTR -> "wstr" ; Match : LPCWSTR -> "wstr" ; FileNameStop : LPWSTR* optional, out -> "var" ; MatchStop : LPWSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SymMatchFileNameW(LPCWSTR FileName, LPCWSTR Match, LPWSTR* FileNameStop, LPWSTR* MatchStop) #uselib "dbghelp.dll" #cfunc global SymMatchFileNameW "SymMatchFileNameW" wstr, wstr, intptr, intptr ; res = SymMatchFileNameW(FileName, Match, varptr(FileNameStop), varptr(MatchStop)) ; FileName : LPCWSTR -> "wstr" ; Match : LPCWSTR -> "wstr" ; FileNameStop : LPWSTR* optional, out -> "intptr" ; MatchStop : LPWSTR* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procSymMatchFileNameW = dbghelp.NewProc("SymMatchFileNameW")
)
// FileName (LPCWSTR), Match (LPCWSTR), FileNameStop (LPWSTR* optional, out), MatchStop (LPWSTR* optional, out)
r1, _, err := procSymMatchFileNameW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Match))),
uintptr(FileNameStop),
uintptr(MatchStop),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SymMatchFileNameW(
FileName: PWideChar; // LPCWSTR
Match: PWideChar; // LPCWSTR
FileNameStop: PPWideChar; // LPWSTR* optional, out
MatchStop: PPWideChar // LPWSTR* optional, out
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymMatchFileNameW';result := DllCall("dbghelp\SymMatchFileNameW"
, "WStr", FileName ; LPCWSTR
, "WStr", Match ; LPCWSTR
, "Ptr", FileNameStop ; LPWSTR* optional, out
, "Ptr", MatchStop ; LPWSTR* optional, out
, "Int") ; return: BOOL●SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop) = DLL("dbghelp.dll", "bool SymMatchFileNameW(char*, char*, void*, void*)")
# 呼び出し: SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop)
# FileName : LPCWSTR -> "char*"
# Match : LPCWSTR -> "char*"
# FileNameStop : LPWSTR* optional, out -> "void*"
# MatchStop : LPWSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "dbghelp" fn SymMatchFileNameW(
FileName: [*c]const u16, // LPCWSTR
Match: [*c]const u16, // LPCWSTR
FileNameStop: [*c][*c]u16, // LPWSTR* optional, out
MatchStop: [*c][*c]u16 // LPWSTR* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SymMatchFileNameW(
FileName: WideCString, # LPCWSTR
Match: WideCString, # LPCWSTR
FileNameStop: ptr WideCString, # LPWSTR* optional, out
MatchStop: ptr WideCString # LPWSTR* optional, out
): int32 {.importc: "SymMatchFileNameW", stdcall, dynlib: "dbghelp.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "dbghelp");
extern(Windows)
int SymMatchFileNameW(
const(wchar)* FileName, // LPCWSTR
const(wchar)* Match, // LPCWSTR
wchar** FileNameStop, // LPWSTR* optional, out
wchar** MatchStop // LPWSTR* optional, out
);ccall((:SymMatchFileNameW, "dbghelp.dll"), stdcall, Int32,
(Cwstring, Cwstring, Ptr{Ptr{UInt16}}, Ptr{Ptr{UInt16}}),
FileName, Match, FileNameStop, MatchStop)
# FileName : LPCWSTR -> Cwstring
# Match : LPCWSTR -> Cwstring
# FileNameStop : LPWSTR* optional, out -> Ptr{Ptr{UInt16}}
# MatchStop : LPWSTR* optional, out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SymMatchFileNameW(
const uint16_t* FileName,
const uint16_t* Match,
uint16_t** FileNameStop,
uint16_t** MatchStop);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop)
-- FileName : LPCWSTR
-- Match : LPCWSTR
-- FileNameStop : LPWSTR* optional, out
-- MatchStop : LPWSTR* optional, out
-- 構造体/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 SymMatchFileNameW = lib.func('__stdcall', 'SymMatchFileNameW', 'int32_t', ['str16', 'str16', 'void *', 'void *']);
// SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop)
// FileName : LPCWSTR -> 'str16'
// Match : LPCWSTR -> 'str16'
// FileNameStop : LPWSTR* optional, out -> 'void *'
// MatchStop : LPWSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("dbghelp.dll", {
SymMatchFileNameW: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop)
// FileName : LPCWSTR -> "buffer"
// Match : LPCWSTR -> "buffer"
// FileNameStop : LPWSTR* optional, out -> "pointer"
// MatchStop : LPWSTR* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SymMatchFileNameW(
const uint16_t* FileName,
const uint16_t* Match,
uint16_t** FileNameStop,
uint16_t** MatchStop);
C, "dbghelp.dll");
// $ffi->SymMatchFileNameW(FileName, Match, FileNameStop, MatchStop);
// FileName : LPCWSTR
// Match : LPCWSTR
// FileNameStop : LPWSTR* optional, out
// MatchStop : LPWSTR* optional, out
// 構造体/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 SymMatchFileNameW(
WString FileName, // LPCWSTR
WString Match, // LPCWSTR
PointerByReference FileNameStop, // LPWSTR* optional, out
PointerByReference MatchStop // LPWSTR* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("dbghelp")]
lib Libdbghelp
fun SymMatchFileNameW = SymMatchFileNameW(
FileName : UInt16*, # LPCWSTR
Match : UInt16*, # LPCWSTR
FileNameStop : UInt16**, # LPWSTR* optional, out
MatchStop : UInt16** # LPWSTR* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SymMatchFileNameWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
typedef SymMatchFileNameWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
final SymMatchFileNameW = DynamicLibrary.open('dbghelp.dll')
.lookupFunction<SymMatchFileNameWNative, SymMatchFileNameWDart>('SymMatchFileNameW');
// FileName : LPCWSTR -> Pointer<Utf16>
// Match : LPCWSTR -> Pointer<Utf16>
// FileNameStop : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// MatchStop : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SymMatchFileNameW(
FileName: PWideChar; // LPCWSTR
Match: PWideChar; // LPCWSTR
FileNameStop: PPWideChar; // LPWSTR* optional, out
MatchStop: PPWideChar // LPWSTR* optional, out
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymMatchFileNameW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SymMatchFileNameW"
c_SymMatchFileNameW :: CWString -> CWString -> Ptr CWString -> Ptr CWString -> IO CInt
-- FileName : LPCWSTR -> CWString
-- Match : LPCWSTR -> CWString
-- FileNameStop : LPWSTR* optional, out -> Ptr CWString
-- MatchStop : LPWSTR* optional, out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let symmatchfilenamew =
foreign "SymMatchFileNameW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* FileName : LPCWSTR -> (ptr uint16_t) *)
(* Match : LPCWSTR -> (ptr uint16_t) *)
(* FileNameStop : LPWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* MatchStop : LPWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)
(cffi:defcfun ("SymMatchFileNameW" sym-match-file-name-w :convention :stdcall) :int32
(file-name (:string :encoding :utf-16le)) ; LPCWSTR
(match (:string :encoding :utf-16le)) ; LPCWSTR
(file-name-stop :pointer) ; LPWSTR* optional, out
(match-stop :pointer)) ; LPWSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SymMatchFileNameW = Win32::API::More->new('dbghelp',
'BOOL SymMatchFileNameW(LPCWSTR FileName, LPCWSTR Match, LPVOID FileNameStop, LPVOID MatchStop)');
# my $ret = $SymMatchFileNameW->Call($FileName, $Match, $FileNameStop, $MatchStop);
# FileName : LPCWSTR -> LPCWSTR
# Match : LPCWSTR -> LPCWSTR
# FileNameStop : LPWSTR* optional, out -> LPVOID
# MatchStop : LPWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。