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