ホーム › System.Diagnostics.Debug › SymGetSourceFileW
SymGetSourceFileW
関数シンボルストアからソースファイルを取得する(Unicode版)。
シグネチャ
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SymGetSourceFileW(
HANDLE hProcess,
ULONGLONG Base,
LPCWSTR Params, // optional
LPCWSTR FileSpec,
LPWSTR FilePath,
DWORD Size
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hProcess | HANDLE | in |
| Base | ULONGLONG | in |
| Params | LPCWSTR | inoptional |
| FileSpec | LPCWSTR | in |
| FilePath | LPWSTR | out |
| Size | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// dbghelp.dll (Unicode / -W)
#include <windows.h>
BOOL SymGetSourceFileW(
HANDLE hProcess,
ULONGLONG Base,
LPCWSTR Params, // optional
LPCWSTR FileSpec,
LPWSTR FilePath,
DWORD Size
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SymGetSourceFileW(
IntPtr hProcess, // HANDLE
ulong Base, // ULONGLONG
[MarshalAs(UnmanagedType.LPWStr)] string Params, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string FileSpec, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder FilePath, // LPWSTR out
uint Size // DWORD
);<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymGetSourceFileW(
hProcess As IntPtr, ' HANDLE
Base As ULong, ' ULONGLONG
<MarshalAs(UnmanagedType.LPWStr)> Params As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> FileSpec As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> FilePath As System.Text.StringBuilder, ' LPWSTR out
Size As UInteger ' DWORD
) As Boolean
End Function' hProcess : HANDLE
' Base : ULONGLONG
' Params : LPCWSTR optional
' FileSpec : LPCWSTR
' FilePath : LPWSTR out
' Size : DWORD
Declare PtrSafe Function SymGetSourceFileW Lib "dbghelp" ( _
ByVal hProcess As LongPtr, _
ByVal Base As LongLong, _
ByVal Params As LongPtr, _
ByVal FileSpec As LongPtr, _
ByVal FilePath As LongPtr, _
ByVal Size As Long) 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
SymGetSourceFileW = ctypes.windll.dbghelp.SymGetSourceFileW
SymGetSourceFileW.restype = wintypes.BOOL
SymGetSourceFileW.argtypes = [
wintypes.HANDLE, # hProcess : HANDLE
ctypes.c_ulonglong, # Base : ULONGLONG
wintypes.LPCWSTR, # Params : LPCWSTR optional
wintypes.LPCWSTR, # FileSpec : LPCWSTR
wintypes.LPWSTR, # FilePath : LPWSTR out
wintypes.DWORD, # Size : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
SymGetSourceFileW = Fiddle::Function.new(
lib['SymGetSourceFileW'],
[
Fiddle::TYPE_VOIDP, # hProcess : HANDLE
-Fiddle::TYPE_LONG_LONG, # Base : ULONGLONG
Fiddle::TYPE_VOIDP, # Params : LPCWSTR optional
Fiddle::TYPE_VOIDP, # FileSpec : LPCWSTR
Fiddle::TYPE_VOIDP, # FilePath : LPWSTR out
-Fiddle::TYPE_INT, # Size : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "dbghelp")]
extern "system" {
fn SymGetSourceFileW(
hProcess: *mut core::ffi::c_void, // HANDLE
Base: u64, // ULONGLONG
Params: *const u16, // LPCWSTR optional
FileSpec: *const u16, // LPCWSTR
FilePath: *mut u16, // LPWSTR out
Size: u32 // DWORD
) -> 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 SymGetSourceFileW(IntPtr hProcess, ulong Base, [MarshalAs(UnmanagedType.LPWStr)] string Params, [MarshalAs(UnmanagedType.LPWStr)] string FileSpec, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder FilePath, uint Size);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymGetSourceFileW' -Namespace Win32 -PassThru
# $api::SymGetSourceFileW(hProcess, Base, Params, FileSpec, FilePath, Size)#uselib "dbghelp.dll"
#func global SymGetSourceFileW "SymGetSourceFileW" wptr, wptr, wptr, wptr, wptr, wptr
; SymGetSourceFileW hProcess, Base, Params, FileSpec, varptr(FilePath), Size ; 戻り値は stat
; hProcess : HANDLE -> "wptr"
; Base : ULONGLONG -> "wptr"
; Params : LPCWSTR optional -> "wptr"
; FileSpec : LPCWSTR -> "wptr"
; FilePath : LPWSTR out -> "wptr"
; Size : DWORD -> "wptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "dbghelp.dll" #cfunc global SymGetSourceFileW "SymGetSourceFileW" sptr, int64, wstr, wstr, var, int ; res = SymGetSourceFileW(hProcess, Base, Params, FileSpec, FilePath, Size) ; hProcess : HANDLE -> "sptr" ; Base : ULONGLONG -> "int64" ; Params : LPCWSTR optional -> "wstr" ; FileSpec : LPCWSTR -> "wstr" ; FilePath : LPWSTR out -> "var" ; Size : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "dbghelp.dll" #cfunc global SymGetSourceFileW "SymGetSourceFileW" sptr, int64, wstr, wstr, sptr, int ; res = SymGetSourceFileW(hProcess, Base, Params, FileSpec, varptr(FilePath), Size) ; hProcess : HANDLE -> "sptr" ; Base : ULONGLONG -> "int64" ; Params : LPCWSTR optional -> "wstr" ; FileSpec : LPCWSTR -> "wstr" ; FilePath : LPWSTR out -> "sptr" ; Size : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; BOOL SymGetSourceFileW(HANDLE hProcess, ULONGLONG Base, LPCWSTR Params, LPCWSTR FileSpec, LPWSTR FilePath, DWORD Size) #uselib "dbghelp.dll" #cfunc global SymGetSourceFileW "SymGetSourceFileW" intptr, int64, wstr, wstr, var, int ; res = SymGetSourceFileW(hProcess, Base, Params, FileSpec, FilePath, Size) ; hProcess : HANDLE -> "intptr" ; Base : ULONGLONG -> "int64" ; Params : LPCWSTR optional -> "wstr" ; FileSpec : LPCWSTR -> "wstr" ; FilePath : LPWSTR out -> "var" ; Size : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SymGetSourceFileW(HANDLE hProcess, ULONGLONG Base, LPCWSTR Params, LPCWSTR FileSpec, LPWSTR FilePath, DWORD Size) #uselib "dbghelp.dll" #cfunc global SymGetSourceFileW "SymGetSourceFileW" intptr, int64, wstr, wstr, intptr, int ; res = SymGetSourceFileW(hProcess, Base, Params, FileSpec, varptr(FilePath), Size) ; hProcess : HANDLE -> "intptr" ; Base : ULONGLONG -> "int64" ; Params : LPCWSTR optional -> "wstr" ; FileSpec : LPCWSTR -> "wstr" ; FilePath : LPWSTR out -> "intptr" ; Size : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procSymGetSourceFileW = dbghelp.NewProc("SymGetSourceFileW")
)
// hProcess (HANDLE), Base (ULONGLONG), Params (LPCWSTR optional), FileSpec (LPCWSTR), FilePath (LPWSTR out), Size (DWORD)
r1, _, err := procSymGetSourceFileW.Call(
uintptr(hProcess),
uintptr(Base),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Params))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileSpec))),
uintptr(FilePath),
uintptr(Size),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SymGetSourceFileW(
hProcess: THandle; // HANDLE
Base: UInt64; // ULONGLONG
Params: PWideChar; // LPCWSTR optional
FileSpec: PWideChar; // LPCWSTR
FilePath: PWideChar; // LPWSTR out
Size: DWORD // DWORD
): BOOL; stdcall;
external 'dbghelp.dll' name 'SymGetSourceFileW';result := DllCall("dbghelp\SymGetSourceFileW"
, "Ptr", hProcess ; HANDLE
, "Int64", Base ; ULONGLONG
, "WStr", Params ; LPCWSTR optional
, "WStr", FileSpec ; LPCWSTR
, "Ptr", FilePath ; LPWSTR out
, "UInt", Size ; DWORD
, "Int") ; return: BOOL●SymGetSourceFileW(hProcess, Base, Params, FileSpec, FilePath, Size) = DLL("dbghelp.dll", "bool SymGetSourceFileW(void*, qword, char*, char*, char*, dword)")
# 呼び出し: SymGetSourceFileW(hProcess, Base, Params, FileSpec, FilePath, Size)
# hProcess : HANDLE -> "void*"
# Base : ULONGLONG -> "qword"
# Params : LPCWSTR optional -> "char*"
# FileSpec : LPCWSTR -> "char*"
# FilePath : LPWSTR out -> "char*"
# Size : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。