ホーム › System.Diagnostics.Debug › SymMatchFileName
SymMatchFileName
関数ファイル名がパターンに一致するか比較照合する。
シグネチャ
// dbghelp.dll (ANSI / -A)
#include <windows.h>
BOOL SymMatchFileName(
LPCSTR FileName,
LPCSTR Match,
LPSTR* FileNameStop, // optional
LPSTR* MatchStop // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCSTR | in | Match パラメーターと比較されるファイル名です。 |
| Match | LPCSTR | in | FileName パラメーターと比較される文字列です。 |
| FileNameStop | LPSTR* | outoptional | FileName 内で照合が停止した位置へのポインターを受け取る文字列バッファーへのポインターです。完全に一致した場合、この値は FileName の 1 文字前になることがあります。この値は NULL にすることもできます。 |
| MatchStop | LPSTR* | outoptional | Match 内で照合が停止した位置へのポインターを受け取る文字列バッファーへのポインターです。完全に一致した場合、この値は Match の 1 文字前になることがあります。この値は NULL にすることもできます。 |
戻り値の型: BOOL
公式ドキュメント
SymMatchFileName 関数 (dbghelp.h) は、文字列をファイル名およびパスと比較します。
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
照合する文字列は完全なファイル名のサフィックスにできるため、この関数を使用して、プレーンなファイル名を完全修飾ファイル名と照合できます。
照合は両方の文字列の末尾から開始され、後方に向かって進みます。照合は大文字と小文字を区別せず、バックスラッシュ (\) とスラッシュ (/) を同一視します。
この関数を含むすべての DbgHelp 関数はシングルスレッドです。したがって、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
この関数の Unicode バージョンを呼び出すには、DBGHELP_TRANSLATE_TCHAR を定義します。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 (ANSI / -A)
#include <windows.h>
BOOL SymMatchFileName(
LPCSTR FileName,
LPCSTR Match,
LPSTR* FileNameStop, // optional
LPSTR* MatchStop // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SymMatchFileName(
[MarshalAs(UnmanagedType.LPStr)] string FileName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string Match, // LPCSTR
IntPtr FileNameStop, // LPSTR* optional, out
IntPtr MatchStop // LPSTR* optional, out
);<DllImport("dbghelp.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymMatchFileName(
<MarshalAs(UnmanagedType.LPStr)> FileName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> Match As String, ' LPCSTR
FileNameStop As IntPtr, ' LPSTR* optional, out
MatchStop As IntPtr ' LPSTR* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' FileName : LPCSTR
' Match : LPCSTR
' FileNameStop : LPSTR* optional, out
' MatchStop : LPSTR* optional, out
Declare PtrSafe Function SymMatchFileName Lib "dbghelp" ( _
ByVal FileName As String, _
ByVal Match As String, _
ByVal FileNameStop As LongPtr, _
ByVal MatchStop As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SymMatchFileName = ctypes.windll.dbghelp.SymMatchFileName
SymMatchFileName.restype = wintypes.BOOL
SymMatchFileName.argtypes = [
wintypes.LPCSTR, # FileName : LPCSTR
wintypes.LPCSTR, # Match : LPCSTR
ctypes.c_void_p, # FileNameStop : LPSTR* optional, out
ctypes.c_void_p, # MatchStop : LPSTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
SymMatchFileName = Fiddle::Function.new(
lib['SymMatchFileName'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCSTR
Fiddle::TYPE_VOIDP, # Match : LPCSTR
Fiddle::TYPE_VOIDP, # FileNameStop : LPSTR* optional, out
Fiddle::TYPE_VOIDP, # MatchStop : LPSTR* optional, out
],
Fiddle::TYPE_INT)#[link(name = "dbghelp")]
extern "system" {
fn SymMatchFileName(
FileName: *const u8, // LPCSTR
Match: *const u8, // LPCSTR
FileNameStop: *mut *mut u8, // LPSTR* optional, out
MatchStop: *mut *mut u8 // LPSTR* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SymMatchFileName([MarshalAs(UnmanagedType.LPStr)] string FileName, [MarshalAs(UnmanagedType.LPStr)] string Match, IntPtr FileNameStop, IntPtr MatchStop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymMatchFileName' -Namespace Win32 -PassThru
# $api::SymMatchFileName(FileName, Match, FileNameStop, MatchStop)#uselib "dbghelp.dll"
#func global SymMatchFileName "SymMatchFileName" sptr, sptr, sptr, sptr
; SymMatchFileName FileName, Match, varptr(FileNameStop), varptr(MatchStop) ; 戻り値は stat
; FileName : LPCSTR -> "sptr"
; Match : LPCSTR -> "sptr"
; FileNameStop : LPSTR* optional, out -> "sptr"
; MatchStop : LPSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "dbghelp.dll" #cfunc global SymMatchFileName "SymMatchFileName" str, str, var, var ; res = SymMatchFileName(FileName, Match, FileNameStop, MatchStop) ; FileName : LPCSTR -> "str" ; Match : LPCSTR -> "str" ; FileNameStop : LPSTR* optional, out -> "var" ; MatchStop : LPSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dbghelp.dll" #cfunc global SymMatchFileName "SymMatchFileName" str, str, sptr, sptr ; res = SymMatchFileName(FileName, Match, varptr(FileNameStop), varptr(MatchStop)) ; FileName : LPCSTR -> "str" ; Match : LPCSTR -> "str" ; FileNameStop : LPSTR* optional, out -> "sptr" ; MatchStop : LPSTR* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SymMatchFileName(LPCSTR FileName, LPCSTR Match, LPSTR* FileNameStop, LPSTR* MatchStop) #uselib "dbghelp.dll" #cfunc global SymMatchFileName "SymMatchFileName" str, str, var, var ; res = SymMatchFileName(FileName, Match, FileNameStop, MatchStop) ; FileName : LPCSTR -> "str" ; Match : LPCSTR -> "str" ; FileNameStop : LPSTR* optional, out -> "var" ; MatchStop : LPSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SymMatchFileName(LPCSTR FileName, LPCSTR Match, LPSTR* FileNameStop, LPSTR* MatchStop) #uselib "dbghelp.dll" #cfunc global SymMatchFileName "SymMatchFileName" str, str, intptr, intptr ; res = SymMatchFileName(FileName, Match, varptr(FileNameStop), varptr(MatchStop)) ; FileName : LPCSTR -> "str" ; Match : LPCSTR -> "str" ; FileNameStop : LPSTR* optional, out -> "intptr" ; MatchStop : LPSTR* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procSymMatchFileName = dbghelp.NewProc("SymMatchFileName")
)
// FileName (LPCSTR), Match (LPCSTR), FileNameStop (LPSTR* optional, out), MatchStop (LPSTR* optional, out)
r1, _, err := procSymMatchFileName.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(FileName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(Match))),
uintptr(FileNameStop),
uintptr(MatchStop),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SymMatchFileName(
FileName: PAnsiChar; // LPCSTR
Match: PAnsiChar; // LPCSTR
FileNameStop: PPAnsiChar; // LPSTR* optional, out
MatchStop: PPAnsiChar // LPSTR* optional, out
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymMatchFileName';result := DllCall("dbghelp\SymMatchFileName"
, "AStr", FileName ; LPCSTR
, "AStr", Match ; LPCSTR
, "Ptr", FileNameStop ; LPSTR* optional, out
, "Ptr", MatchStop ; LPSTR* optional, out
, "Int") ; return: BOOL●SymMatchFileName(FileName, Match, FileNameStop, MatchStop) = DLL("dbghelp.dll", "bool SymMatchFileName(char*, char*, void*, void*)")
# 呼び出し: SymMatchFileName(FileName, Match, FileNameStop, MatchStop)
# FileName : LPCSTR -> "char*"
# Match : LPCSTR -> "char*"
# FileNameStop : LPSTR* optional, out -> "void*"
# MatchStop : LPSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dbghelp" fn SymMatchFileName(
FileName: [*c]const u8, // LPCSTR
Match: [*c]const u8, // LPCSTR
FileNameStop: [*c][*c]u8, // LPSTR* optional, out
MatchStop: [*c][*c]u8 // LPSTR* optional, out
) callconv(std.os.windows.WINAPI) i32;proc SymMatchFileName(
FileName: cstring, # LPCSTR
Match: cstring, # LPCSTR
FileNameStop: ptr cstring, # LPSTR* optional, out
MatchStop: ptr cstring # LPSTR* optional, out
): int32 {.importc: "SymMatchFileName", stdcall, dynlib: "dbghelp.dll".}pragma(lib, "dbghelp");
extern(Windows)
int SymMatchFileName(
const(char)* FileName, // LPCSTR
const(char)* Match, // LPCSTR
char** FileNameStop, // LPSTR* optional, out
char** MatchStop // LPSTR* optional, out
);ccall((:SymMatchFileName, "dbghelp.dll"), stdcall, Int32,
(Cstring, Cstring, Ptr{Ptr{UInt8}}, Ptr{Ptr{UInt8}}),
FileName, Match, FileNameStop, MatchStop)
# FileName : LPCSTR -> Cstring
# Match : LPCSTR -> Cstring
# FileNameStop : LPSTR* optional, out -> Ptr{Ptr{UInt8}}
# MatchStop : LPSTR* optional, out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SymMatchFileName(
const char* FileName,
const char* Match,
char** FileNameStop,
char** MatchStop);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.SymMatchFileName(FileName, Match, FileNameStop, MatchStop)
-- FileName : LPCSTR
-- Match : LPCSTR
-- FileNameStop : LPSTR* optional, out
-- MatchStop : LPSTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const SymMatchFileName = lib.func('__stdcall', 'SymMatchFileName', 'int32_t', ['str', 'str', 'void *', 'void *']);
// SymMatchFileName(FileName, Match, FileNameStop, MatchStop)
// FileName : LPCSTR -> 'str'
// Match : LPCSTR -> 'str'
// FileNameStop : LPSTR* optional, out -> 'void *'
// MatchStop : LPSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("dbghelp.dll", {
SymMatchFileName: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SymMatchFileName(FileName, Match, FileNameStop, MatchStop)
// FileName : LPCSTR -> "buffer"
// Match : LPCSTR -> "buffer"
// FileNameStop : LPSTR* optional, out -> "pointer"
// MatchStop : LPSTR* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SymMatchFileName(
const char* FileName,
const char* Match,
char** FileNameStop,
char** MatchStop);
C, "dbghelp.dll");
// $ffi->SymMatchFileName(FileName, Match, FileNameStop, MatchStop);
// FileName : LPCSTR
// Match : LPCSTR
// FileNameStop : LPSTR* optional, out
// MatchStop : LPSTR* 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.ASCII_OPTIONS);
boolean SymMatchFileName(
String FileName, // LPCSTR
String Match, // LPCSTR
PointerByReference FileNameStop, // LPSTR* optional, out
PointerByReference MatchStop // LPSTR* optional, out
);
}@[Link("dbghelp")]
lib Libdbghelp
fun SymMatchFileName = SymMatchFileName(
FileName : UInt8*, # LPCSTR
Match : UInt8*, # LPCSTR
FileNameStop : UInt8**, # LPSTR* optional, out
MatchStop : UInt8** # LPSTR* 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 SymMatchFileNameNative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Pointer<Utf8>>, Pointer<Pointer<Utf8>>);
typedef SymMatchFileNameDart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Pointer<Utf8>>, Pointer<Pointer<Utf8>>);
final SymMatchFileName = DynamicLibrary.open('dbghelp.dll')
.lookupFunction<SymMatchFileNameNative, SymMatchFileNameDart>('SymMatchFileName');
// FileName : LPCSTR -> Pointer<Utf8>
// Match : LPCSTR -> Pointer<Utf8>
// FileNameStop : LPSTR* optional, out -> Pointer<Pointer<Utf8>>
// MatchStop : LPSTR* optional, out -> Pointer<Pointer<Utf8>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SymMatchFileName(
FileName: PAnsiChar; // LPCSTR
Match: PAnsiChar; // LPCSTR
FileNameStop: PPAnsiChar; // LPSTR* optional, out
MatchStop: PPAnsiChar // LPSTR* optional, out
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymMatchFileName';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SymMatchFileName"
c_SymMatchFileName :: CString -> CString -> Ptr CString -> Ptr CString -> IO CInt
-- FileName : LPCSTR -> CString
-- Match : LPCSTR -> CString
-- FileNameStop : LPSTR* optional, out -> Ptr CString
-- MatchStop : LPSTR* optional, out -> Ptr CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let symmatchfilename =
foreign "SymMatchFileName"
(string @-> string @-> (ptr string) @-> (ptr string) @-> returning int32_t)
(* FileName : LPCSTR -> string *)
(* Match : LPCSTR -> string *)
(* FileNameStop : LPSTR* optional, out -> (ptr string) *)
(* MatchStop : LPSTR* optional, out -> (ptr string) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)
(cffi:defcfun ("SymMatchFileName" sym-match-file-name :convention :stdcall) :int32
(file-name :string) ; LPCSTR
(match :string) ; LPCSTR
(file-name-stop :pointer) ; LPSTR* optional, out
(match-stop :pointer)) ; LPSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SymMatchFileName = Win32::API::More->new('dbghelp',
'BOOL SymMatchFileName(LPCSTR FileName, LPCSTR Match, LPVOID FileNameStop, LPVOID MatchStop)');
# my $ret = $SymMatchFileName->Call($FileName, $Match, $FileNameStop, $MatchStop);
# FileName : LPCSTR -> LPCSTR
# Match : LPCSTR -> LPCSTR
# FileNameStop : LPSTR* optional, out -> LPVOID
# MatchStop : LPSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SymMatchFileNameW (Unicode版) — ファイル名がパターンに一致するか照合する(Unicode版)。