SymFindFileInPathW
関数シグネチャ
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SymFindFileInPathW(
HANDLE hprocess,
LPCWSTR SearchPathA, // optional
LPCWSTR FileName,
void* id, // optional
DWORD two,
DWORD three,
SYM_FIND_ID_OPTION flags,
LPWSTR FoundFile,
PFINDFILEINPATHCALLBACKW callback, // optional
void* context // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| hprocess | HANDLE | in | 元々 SymInitialize 関数に渡されたプロセスへのハンドル。 | ||||||||
| SearchPathA | LPCWSTR | inoptional | ファイルを検索するパスを指すワイド文字列へのポインタ。NULLで設定済みパス。 | ||||||||
| FileName | LPCWSTR | in | ファイルの名前。パスを指定することもできますが、使用されるのはファイル名のみです。 | ||||||||
| id | void* | inoptional | 3 つの識別パラメーターのうち最初のもの(「解説」を参照)。 | ||||||||
| two | DWORD | in | 3 つの識別パラメーターのうち 2 番目のもの(「解説」を参照)。 | ||||||||
| three | DWORD | in | 3 つの識別パラメーターのうち 3 番目のもの(「解説」を参照)。 | ||||||||
| flags | SYM_FIND_ID_OPTION | in | id パラメーターの形式。このパラメーターには、次のいずれかの値を指定できます。
| ||||||||
| FoundFile | LPWSTR | out | シンボルファイルへの完全修飾パスを受け取るバッファーへのポインター。このバッファーは少なくとも MAX_PATH+1 文字の長さが必要です。 | ||||||||
| callback | PFINDFILEINPATHCALLBACKW | inoptional | SymFindFileInPathProc コールバック関数。 | ||||||||
| context | void* | inoptional | ユーザー定義の値または NULL。この値は単にコールバック関数へ渡されます。このパラメーターは通常、コールバック関数に何らかのコンテキストを提供するデータ構造へのポインターをアプリケーションが渡すために使用されます。 |
戻り値の型: BOOL
公式ドキュメント
SymFindFileInPathW (Unicode) 関数は、シンボルファイルまたは実行可能イメージの場所を特定します。
戻り値
サーバーが有効なシンボルファイルの場所を特定した場合は TRUE を返します。それ以外の場合は FALSE を返し、 GetLastError がシンボルファイルが返されなかった理由を示す値を返します。
解説(Remarks)
識別パラメーターには、次のように値が設定されます。
- DbgHelp が .pdb ファイルを探している場合、id パラメーターには元のイメージの codeview デバッグディレクトリにある PDB シグネチャを指定します。two パラメーターには PDB の経過情報 (age) を指定します。three パラメーターは使用されず、ゼロに設定します。
- DbgHelp が実行可能ファイルや .dbg ファイルなど、その他の種類のイメージを探している場合、id パラメーターには元のイメージの PE ヘッダーにある TimeDateStamp を指定します。two パラメーターには、同じく PE ヘッダーから取得した SizeOfImage フィールドを指定します。three パラメーターは使用されず、ゼロに設定します。
ディレクトリを検索する場合、この関数は既定ではシンボル識別子が一致するかどうかを検証しません。一致するシンボルファイルが確実に検出されるようにするには、SymSetOptions 関数を SYMOPT_EXACT_SYMBOLS を指定して呼び出してください。
この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
この関数の Unicode バージョンを呼び出すには、DBGHELP_TRANSLATE_TCHAR を定義します。
dbghelp.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI バージョンまたは Unicode バージョンを自動的に選択するエイリアスとして SymFindFileInPath を定義します。エンコード中立のエイリアスの使用を、エンコード中立でないコードと混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SymFindFileInPathW(
HANDLE hprocess,
LPCWSTR SearchPathA, // optional
LPCWSTR FileName,
void* id, // optional
DWORD two,
DWORD three,
SYM_FIND_ID_OPTION flags,
LPWSTR FoundFile,
PFINDFILEINPATHCALLBACKW callback, // optional
void* context // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SymFindFileInPathW(
IntPtr hprocess, // HANDLE
[MarshalAs(UnmanagedType.LPWStr)] string SearchPathA, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string FileName, // LPCWSTR
IntPtr id, // void* optional
uint two, // DWORD
uint three, // DWORD
uint flags, // SYM_FIND_ID_OPTION
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder FoundFile, // LPWSTR out
IntPtr callback, // PFINDFILEINPATHCALLBACKW optional
IntPtr context // void* optional
);<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymFindFileInPathW(
hprocess As IntPtr, ' HANDLE
<MarshalAs(UnmanagedType.LPWStr)> SearchPathA As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> FileName As String, ' LPCWSTR
id As IntPtr, ' void* optional
two As UInteger, ' DWORD
three As UInteger, ' DWORD
flags As UInteger, ' SYM_FIND_ID_OPTION
<MarshalAs(UnmanagedType.LPWStr)> FoundFile As System.Text.StringBuilder, ' LPWSTR out
callback As IntPtr, ' PFINDFILEINPATHCALLBACKW optional
context As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hprocess : HANDLE
' SearchPathA : LPCWSTR optional
' FileName : LPCWSTR
' id : void* optional
' two : DWORD
' three : DWORD
' flags : SYM_FIND_ID_OPTION
' FoundFile : LPWSTR out
' callback : PFINDFILEINPATHCALLBACKW optional
' context : void* optional
Declare PtrSafe Function SymFindFileInPathW Lib "dbghelp" ( _
ByVal hprocess As LongPtr, _
ByVal SearchPathA As LongPtr, _
ByVal FileName As LongPtr, _
ByVal id As LongPtr, _
ByVal two As Long, _
ByVal three As Long, _
ByVal flags As Long, _
ByVal FoundFile As LongPtr, _
ByVal callback As LongPtr, _
ByVal context 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
SymFindFileInPathW = ctypes.windll.dbghelp.SymFindFileInPathW
SymFindFileInPathW.restype = wintypes.BOOL
SymFindFileInPathW.argtypes = [
wintypes.HANDLE, # hprocess : HANDLE
wintypes.LPCWSTR, # SearchPathA : LPCWSTR optional
wintypes.LPCWSTR, # FileName : LPCWSTR
ctypes.POINTER(None), # id : void* optional
wintypes.DWORD, # two : DWORD
wintypes.DWORD, # three : DWORD
wintypes.DWORD, # flags : SYM_FIND_ID_OPTION
wintypes.LPWSTR, # FoundFile : LPWSTR out
ctypes.c_void_p, # callback : PFINDFILEINPATHCALLBACKW optional
ctypes.POINTER(None), # context : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
SymFindFileInPathW = Fiddle::Function.new(
lib['SymFindFileInPathW'],
[
Fiddle::TYPE_VOIDP, # hprocess : HANDLE
Fiddle::TYPE_VOIDP, # SearchPathA : LPCWSTR optional
Fiddle::TYPE_VOIDP, # FileName : LPCWSTR
Fiddle::TYPE_VOIDP, # id : void* optional
-Fiddle::TYPE_INT, # two : DWORD
-Fiddle::TYPE_INT, # three : DWORD
-Fiddle::TYPE_INT, # flags : SYM_FIND_ID_OPTION
Fiddle::TYPE_VOIDP, # FoundFile : LPWSTR out
Fiddle::TYPE_VOIDP, # callback : PFINDFILEINPATHCALLBACKW optional
Fiddle::TYPE_VOIDP, # context : void* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "dbghelp")]
extern "system" {
fn SymFindFileInPathW(
hprocess: *mut core::ffi::c_void, // HANDLE
SearchPathA: *const u16, // LPCWSTR optional
FileName: *const u16, // LPCWSTR
id: *mut (), // void* optional
two: u32, // DWORD
three: u32, // DWORD
flags: u32, // SYM_FIND_ID_OPTION
FoundFile: *mut u16, // LPWSTR out
callback: *const core::ffi::c_void, // PFINDFILEINPATHCALLBACKW optional
context: *mut () // void* optional
) -> 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 SymFindFileInPathW(IntPtr hprocess, [MarshalAs(UnmanagedType.LPWStr)] string SearchPathA, [MarshalAs(UnmanagedType.LPWStr)] string FileName, IntPtr id, uint two, uint three, uint flags, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder FoundFile, IntPtr callback, IntPtr context);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymFindFileInPathW' -Namespace Win32 -PassThru
# $api::SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context)#uselib "dbghelp.dll"
#func global SymFindFileInPathW "SymFindFileInPathW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SymFindFileInPathW hprocess, SearchPathA, FileName, id, two, three, flags, varptr(FoundFile), callback, context ; 戻り値は stat
; hprocess : HANDLE -> "wptr"
; SearchPathA : LPCWSTR optional -> "wptr"
; FileName : LPCWSTR -> "wptr"
; id : void* optional -> "wptr"
; two : DWORD -> "wptr"
; three : DWORD -> "wptr"
; flags : SYM_FIND_ID_OPTION -> "wptr"
; FoundFile : LPWSTR out -> "wptr"
; callback : PFINDFILEINPATHCALLBACKW optional -> "wptr"
; context : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "dbghelp.dll" #cfunc global SymFindFileInPathW "SymFindFileInPathW" sptr, wstr, wstr, sptr, int, int, int, var, sptr, sptr ; res = SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context) ; hprocess : HANDLE -> "sptr" ; SearchPathA : LPCWSTR optional -> "wstr" ; FileName : LPCWSTR -> "wstr" ; id : void* optional -> "sptr" ; two : DWORD -> "int" ; three : DWORD -> "int" ; flags : SYM_FIND_ID_OPTION -> "int" ; FoundFile : LPWSTR out -> "var" ; callback : PFINDFILEINPATHCALLBACKW optional -> "sptr" ; context : void* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dbghelp.dll" #cfunc global SymFindFileInPathW "SymFindFileInPathW" sptr, wstr, wstr, sptr, int, int, int, sptr, sptr, sptr ; res = SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, varptr(FoundFile), callback, context) ; hprocess : HANDLE -> "sptr" ; SearchPathA : LPCWSTR optional -> "wstr" ; FileName : LPCWSTR -> "wstr" ; id : void* optional -> "sptr" ; two : DWORD -> "int" ; three : DWORD -> "int" ; flags : SYM_FIND_ID_OPTION -> "int" ; FoundFile : LPWSTR out -> "sptr" ; callback : PFINDFILEINPATHCALLBACKW optional -> "sptr" ; context : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL SymFindFileInPathW(HANDLE hprocess, LPCWSTR SearchPathA, LPCWSTR FileName, void* id, DWORD two, DWORD three, SYM_FIND_ID_OPTION flags, LPWSTR FoundFile, PFINDFILEINPATHCALLBACKW callback, void* context) #uselib "dbghelp.dll" #cfunc global SymFindFileInPathW "SymFindFileInPathW" intptr, wstr, wstr, intptr, int, int, int, var, intptr, intptr ; res = SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context) ; hprocess : HANDLE -> "intptr" ; SearchPathA : LPCWSTR optional -> "wstr" ; FileName : LPCWSTR -> "wstr" ; id : void* optional -> "intptr" ; two : DWORD -> "int" ; three : DWORD -> "int" ; flags : SYM_FIND_ID_OPTION -> "int" ; FoundFile : LPWSTR out -> "var" ; callback : PFINDFILEINPATHCALLBACKW optional -> "intptr" ; context : void* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SymFindFileInPathW(HANDLE hprocess, LPCWSTR SearchPathA, LPCWSTR FileName, void* id, DWORD two, DWORD three, SYM_FIND_ID_OPTION flags, LPWSTR FoundFile, PFINDFILEINPATHCALLBACKW callback, void* context) #uselib "dbghelp.dll" #cfunc global SymFindFileInPathW "SymFindFileInPathW" intptr, wstr, wstr, intptr, int, int, int, intptr, intptr, intptr ; res = SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, varptr(FoundFile), callback, context) ; hprocess : HANDLE -> "intptr" ; SearchPathA : LPCWSTR optional -> "wstr" ; FileName : LPCWSTR -> "wstr" ; id : void* optional -> "intptr" ; two : DWORD -> "int" ; three : DWORD -> "int" ; flags : SYM_FIND_ID_OPTION -> "int" ; FoundFile : LPWSTR out -> "intptr" ; callback : PFINDFILEINPATHCALLBACKW optional -> "intptr" ; context : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procSymFindFileInPathW = dbghelp.NewProc("SymFindFileInPathW")
)
// hprocess (HANDLE), SearchPathA (LPCWSTR optional), FileName (LPCWSTR), id (void* optional), two (DWORD), three (DWORD), flags (SYM_FIND_ID_OPTION), FoundFile (LPWSTR out), callback (PFINDFILEINPATHCALLBACKW optional), context (void* optional)
r1, _, err := procSymFindFileInPathW.Call(
uintptr(hprocess),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SearchPathA))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileName))),
uintptr(id),
uintptr(two),
uintptr(three),
uintptr(flags),
uintptr(FoundFile),
uintptr(callback),
uintptr(context),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SymFindFileInPathW(
hprocess: THandle; // HANDLE
SearchPathA: PWideChar; // LPCWSTR optional
FileName: PWideChar; // LPCWSTR
id: Pointer; // void* optional
two: DWORD; // DWORD
three: DWORD; // DWORD
flags: DWORD; // SYM_FIND_ID_OPTION
FoundFile: PWideChar; // LPWSTR out
callback: Pointer; // PFINDFILEINPATHCALLBACKW optional
context: Pointer // void* optional
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymFindFileInPathW';result := DllCall("dbghelp\SymFindFileInPathW"
, "Ptr", hprocess ; HANDLE
, "WStr", SearchPathA ; LPCWSTR optional
, "WStr", FileName ; LPCWSTR
, "Ptr", id ; void* optional
, "UInt", two ; DWORD
, "UInt", three ; DWORD
, "UInt", flags ; SYM_FIND_ID_OPTION
, "Ptr", FoundFile ; LPWSTR out
, "Ptr", callback ; PFINDFILEINPATHCALLBACKW optional
, "Ptr", context ; void* optional
, "Int") ; return: BOOL●SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context) = DLL("dbghelp.dll", "bool SymFindFileInPathW(void*, char*, char*, void*, dword, dword, dword, char*, void*, void*)")
# 呼び出し: SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context)
# hprocess : HANDLE -> "void*"
# SearchPathA : LPCWSTR optional -> "char*"
# FileName : LPCWSTR -> "char*"
# id : void* optional -> "void*"
# two : DWORD -> "dword"
# three : DWORD -> "dword"
# flags : SYM_FIND_ID_OPTION -> "dword"
# FoundFile : LPWSTR out -> "char*"
# callback : PFINDFILEINPATHCALLBACKW optional -> "void*"
# context : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "dbghelp" fn SymFindFileInPathW(
hprocess: ?*anyopaque, // HANDLE
SearchPathA: [*c]const u16, // LPCWSTR optional
FileName: [*c]const u16, // LPCWSTR
id: ?*anyopaque, // void* optional
two: u32, // DWORD
three: u32, // DWORD
flags: u32, // SYM_FIND_ID_OPTION
FoundFile: [*c]u16, // LPWSTR out
callback: ?*anyopaque, // PFINDFILEINPATHCALLBACKW optional
context: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SymFindFileInPathW(
hprocess: pointer, # HANDLE
SearchPathA: WideCString, # LPCWSTR optional
FileName: WideCString, # LPCWSTR
id: pointer, # void* optional
two: uint32, # DWORD
three: uint32, # DWORD
flags: uint32, # SYM_FIND_ID_OPTION
FoundFile: ptr uint16, # LPWSTR out
callback: pointer, # PFINDFILEINPATHCALLBACKW optional
context: pointer # void* optional
): int32 {.importc: "SymFindFileInPathW", stdcall, dynlib: "dbghelp.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "dbghelp");
extern(Windows)
int SymFindFileInPathW(
void* hprocess, // HANDLE
const(wchar)* SearchPathA, // LPCWSTR optional
const(wchar)* FileName, // LPCWSTR
void* id, // void* optional
uint two, // DWORD
uint three, // DWORD
uint flags, // SYM_FIND_ID_OPTION
wchar* FoundFile, // LPWSTR out
void* callback, // PFINDFILEINPATHCALLBACKW optional
void* context // void* optional
);ccall((:SymFindFileInPathW, "dbghelp.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Cwstring, Ptr{Cvoid}, UInt32, UInt32, UInt32, Ptr{UInt16}, Ptr{Cvoid}, Ptr{Cvoid}),
hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context)
# hprocess : HANDLE -> Ptr{Cvoid}
# SearchPathA : LPCWSTR optional -> Cwstring
# FileName : LPCWSTR -> Cwstring
# id : void* optional -> Ptr{Cvoid}
# two : DWORD -> UInt32
# three : DWORD -> UInt32
# flags : SYM_FIND_ID_OPTION -> UInt32
# FoundFile : LPWSTR out -> Ptr{UInt16}
# callback : PFINDFILEINPATHCALLBACKW optional -> Ptr{Cvoid}
# context : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SymFindFileInPathW(
void* hprocess,
const uint16_t* SearchPathA,
const uint16_t* FileName,
void* id,
uint32_t two,
uint32_t three,
uint32_t flags,
uint16_t* FoundFile,
void* callback,
void* context);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context)
-- hprocess : HANDLE
-- SearchPathA : LPCWSTR optional
-- FileName : LPCWSTR
-- id : void* optional
-- two : DWORD
-- three : DWORD
-- flags : SYM_FIND_ID_OPTION
-- FoundFile : LPWSTR out
-- callback : PFINDFILEINPATHCALLBACKW optional
-- context : void* optional
-- 構造体/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 SymFindFileInPathW = lib.func('__stdcall', 'SymFindFileInPathW', 'int32_t', ['void *', 'str16', 'str16', 'void *', 'uint32_t', 'uint32_t', 'uint32_t', 'uint16_t *', 'void *', 'void *']);
// SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context)
// hprocess : HANDLE -> 'void *'
// SearchPathA : LPCWSTR optional -> 'str16'
// FileName : LPCWSTR -> 'str16'
// id : void* optional -> 'void *'
// two : DWORD -> 'uint32_t'
// three : DWORD -> 'uint32_t'
// flags : SYM_FIND_ID_OPTION -> 'uint32_t'
// FoundFile : LPWSTR out -> 'uint16_t *'
// callback : PFINDFILEINPATHCALLBACKW optional -> 'void *'
// context : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("dbghelp.dll", {
SymFindFileInPathW: { parameters: ["pointer", "buffer", "buffer", "pointer", "u32", "u32", "u32", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context)
// hprocess : HANDLE -> "pointer"
// SearchPathA : LPCWSTR optional -> "buffer"
// FileName : LPCWSTR -> "buffer"
// id : void* optional -> "pointer"
// two : DWORD -> "u32"
// three : DWORD -> "u32"
// flags : SYM_FIND_ID_OPTION -> "u32"
// FoundFile : LPWSTR out -> "buffer"
// callback : PFINDFILEINPATHCALLBACKW optional -> "pointer"
// context : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SymFindFileInPathW(
void* hprocess,
const uint16_t* SearchPathA,
const uint16_t* FileName,
void* id,
uint32_t two,
uint32_t three,
uint32_t flags,
uint16_t* FoundFile,
void* callback,
void* context);
C, "dbghelp.dll");
// $ffi->SymFindFileInPathW(hprocess, SearchPathA, FileName, id, two, three, flags, FoundFile, callback, context);
// hprocess : HANDLE
// SearchPathA : LPCWSTR optional
// FileName : LPCWSTR
// id : void* optional
// two : DWORD
// three : DWORD
// flags : SYM_FIND_ID_OPTION
// FoundFile : LPWSTR out
// callback : PFINDFILEINPATHCALLBACKW optional
// context : void* optional
// 構造体/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 SymFindFileInPathW(
Pointer hprocess, // HANDLE
WString SearchPathA, // LPCWSTR optional
WString FileName, // LPCWSTR
Pointer id, // void* optional
int two, // DWORD
int three, // DWORD
int flags, // SYM_FIND_ID_OPTION
char[] FoundFile, // LPWSTR out
Callback callback, // PFINDFILEINPATHCALLBACKW optional
Pointer context // void* optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("dbghelp")]
lib Libdbghelp
fun SymFindFileInPathW = SymFindFileInPathW(
hprocess : Void*, # HANDLE
SearchPathA : UInt16*, # LPCWSTR optional
FileName : UInt16*, # LPCWSTR
id : Void*, # void* optional
two : UInt32, # DWORD
three : UInt32, # DWORD
flags : UInt32, # SYM_FIND_ID_OPTION
FoundFile : UInt16*, # LPWSTR out
callback : Void*, # PFINDFILEINPATHCALLBACKW optional
context : Void* # void* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SymFindFileInPathWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Uint32, Uint32, Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef SymFindFileInPathWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, int, int, int, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final SymFindFileInPathW = DynamicLibrary.open('dbghelp.dll')
.lookupFunction<SymFindFileInPathWNative, SymFindFileInPathWDart>('SymFindFileInPathW');
// hprocess : HANDLE -> Pointer<Void>
// SearchPathA : LPCWSTR optional -> Pointer<Utf16>
// FileName : LPCWSTR -> Pointer<Utf16>
// id : void* optional -> Pointer<Void>
// two : DWORD -> Uint32
// three : DWORD -> Uint32
// flags : SYM_FIND_ID_OPTION -> Uint32
// FoundFile : LPWSTR out -> Pointer<Utf16>
// callback : PFINDFILEINPATHCALLBACKW optional -> Pointer<Void>
// context : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SymFindFileInPathW(
hprocess: THandle; // HANDLE
SearchPathA: PWideChar; // LPCWSTR optional
FileName: PWideChar; // LPCWSTR
id: Pointer; // void* optional
two: DWORD; // DWORD
three: DWORD; // DWORD
flags: DWORD; // SYM_FIND_ID_OPTION
FoundFile: PWideChar; // LPWSTR out
callback: Pointer; // PFINDFILEINPATHCALLBACKW optional
context: Pointer // void* optional
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymFindFileInPathW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SymFindFileInPathW"
c_SymFindFileInPathW :: Ptr () -> CWString -> CWString -> Ptr () -> Word32 -> Word32 -> Word32 -> CWString -> Ptr () -> Ptr () -> IO CInt
-- hprocess : HANDLE -> Ptr ()
-- SearchPathA : LPCWSTR optional -> CWString
-- FileName : LPCWSTR -> CWString
-- id : void* optional -> Ptr ()
-- two : DWORD -> Word32
-- three : DWORD -> Word32
-- flags : SYM_FIND_ID_OPTION -> Word32
-- FoundFile : LPWSTR out -> CWString
-- callback : PFINDFILEINPATHCALLBACKW optional -> Ptr ()
-- context : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let symfindfileinpathw =
foreign "SymFindFileInPathW"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hprocess : HANDLE -> (ptr void) *)
(* SearchPathA : LPCWSTR optional -> (ptr uint16_t) *)
(* FileName : LPCWSTR -> (ptr uint16_t) *)
(* id : void* optional -> (ptr void) *)
(* two : DWORD -> uint32_t *)
(* three : DWORD -> uint32_t *)
(* flags : SYM_FIND_ID_OPTION -> uint32_t *)
(* FoundFile : LPWSTR out -> (ptr uint16_t) *)
(* callback : PFINDFILEINPATHCALLBACKW optional -> (ptr void) *)
(* context : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)
(cffi:defcfun ("SymFindFileInPathW" sym-find-file-in-path-w :convention :stdcall) :int32
(hprocess :pointer) ; HANDLE
(search-path-a (:string :encoding :utf-16le)) ; LPCWSTR optional
(file-name (:string :encoding :utf-16le)) ; LPCWSTR
(id :pointer) ; void* optional
(two :uint32) ; DWORD
(three :uint32) ; DWORD
(flags :uint32) ; SYM_FIND_ID_OPTION
(found-file :pointer) ; LPWSTR out
(callback :pointer) ; PFINDFILEINPATHCALLBACKW optional
(context :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SymFindFileInPathW = Win32::API::More->new('dbghelp',
'BOOL SymFindFileInPathW(HANDLE hprocess, LPCWSTR SearchPathA, LPCWSTR FileName, LPVOID id, DWORD two, DWORD three, DWORD flags, LPWSTR FoundFile, LPVOID callback, LPVOID context)');
# my $ret = $SymFindFileInPathW->Call($hprocess, $SearchPathA, $FileName, $id, $two, $three, $flags, $FoundFile, $callback, $context);
# hprocess : HANDLE -> HANDLE
# SearchPathA : LPCWSTR optional -> LPCWSTR
# FileName : LPCWSTR -> LPCWSTR
# id : void* optional -> LPVOID
# two : DWORD -> DWORD
# three : DWORD -> DWORD
# flags : SYM_FIND_ID_OPTION -> DWORD
# FoundFile : LPWSTR out -> LPWSTR
# callback : PFINDFILEINPATHCALLBACKW optional -> LPVOID
# context : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f SymInitializeW — プロセスのシンボルハンドラを初期化する(Unicode版)。
- f SymSetSearchPathW — シンボル検索パスを設定する(Unicode版)。
- f SymSrvGetFileIndexInfoW — ファイルのインデックス情報を取得する(Unicode版)。