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

SymGetSymbolFileW

関数
イメージに対応するシンボルファイルを検索取得する(Unicode版)。
DLLdbghelp.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり

シグネチャ

// 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
);

パラメーター

名前方向
hProcessHANDLEinoptional
SymPathLPCWSTRinoptional
ImageFileLPCWSTRin
TypeDWORDin
SymbolFileLPWSTRout
cSymbolFileUINT_PTRin
DbgFileLPWSTRout
cDbgFileUINT_PTRin

戻り値の型: BOOL

各言語での呼び出し定義

// 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 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // BOOL
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';
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 版の利用を推奨。