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

SymAddSourceStreamW

関数
モジュールにソースストリームを追加する(Unicode版)。
DLLdbghelp.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり

シグネチャ

// dbghelp.dll  (Unicode / -W)
#include <windows.h>

BOOL SymAddSourceStreamW(
    HANDLE hProcess,
    ULONGLONG Base,
    LPCWSTR FileSpec,   // optional
    BYTE* Buffer,   // optional
    UINT_PTR Size
);

パラメーター

名前方向
hProcessHANDLEin
BaseULONGLONGin
FileSpecLPCWSTRinoptional
BufferBYTE*inoptional
SizeUINT_PTRin

戻り値の型: BOOL

各言語での呼び出し定義

// dbghelp.dll  (Unicode / -W)
#include <windows.h>

BOOL SymAddSourceStreamW(
    HANDLE hProcess,
    ULONGLONG Base,
    LPCWSTR FileSpec,   // optional
    BYTE* Buffer,   // optional
    UINT_PTR Size
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SymAddSourceStreamW(
    IntPtr hProcess,   // HANDLE
    ulong Base,   // ULONGLONG
    [MarshalAs(UnmanagedType.LPWStr)] string FileSpec,   // LPCWSTR optional
    IntPtr Buffer,   // BYTE* optional
    UIntPtr Size   // UINT_PTR
);
<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymAddSourceStreamW(
    hProcess As IntPtr,   ' HANDLE
    Base As ULong,   ' ULONGLONG
    <MarshalAs(UnmanagedType.LPWStr)> FileSpec As String,   ' LPCWSTR optional
    Buffer As IntPtr,   ' BYTE* optional
    Size As UIntPtr   ' UINT_PTR
) As Boolean
End Function
' hProcess : HANDLE
' Base : ULONGLONG
' FileSpec : LPCWSTR optional
' Buffer : BYTE* optional
' Size : UINT_PTR
Declare PtrSafe Function SymAddSourceStreamW Lib "dbghelp" ( _
    ByVal hProcess As LongPtr, _
    ByVal Base As LongLong, _
    ByVal FileSpec As LongPtr, _
    ByVal Buffer As LongPtr, _
    ByVal Size 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

SymAddSourceStreamW = ctypes.windll.dbghelp.SymAddSourceStreamW
SymAddSourceStreamW.restype = wintypes.BOOL
SymAddSourceStreamW.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    ctypes.c_ulonglong,  # Base : ULONGLONG
    wintypes.LPCWSTR,  # FileSpec : LPCWSTR optional
    ctypes.POINTER(ctypes.c_ubyte),  # Buffer : BYTE* optional
    ctypes.c_size_t,  # Size : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
SymAddSourceStreamW = Fiddle::Function.new(
  lib['SymAddSourceStreamW'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    -Fiddle::TYPE_LONG_LONG,  # Base : ULONGLONG
    Fiddle::TYPE_VOIDP,  # FileSpec : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Buffer : BYTE* optional
    Fiddle::TYPE_UINTPTR_T,  # Size : UINT_PTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "dbghelp")]
extern "system" {
    fn SymAddSourceStreamW(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        Base: u64,  // ULONGLONG
        FileSpec: *const u16,  // LPCWSTR optional
        Buffer: *mut u8,  // BYTE* optional
        Size: 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 SymAddSourceStreamW(IntPtr hProcess, ulong Base, [MarshalAs(UnmanagedType.LPWStr)] string FileSpec, IntPtr Buffer, UIntPtr Size);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymAddSourceStreamW' -Namespace Win32 -PassThru
# $api::SymAddSourceStreamW(hProcess, Base, FileSpec, Buffer, Size)
#uselib "dbghelp.dll"
#func global SymAddSourceStreamW "SymAddSourceStreamW" wptr, wptr, wptr, wptr, wptr
; SymAddSourceStreamW hProcess, Base, FileSpec, varptr(Buffer), Size   ; 戻り値は stat
; hProcess : HANDLE -> "wptr"
; Base : ULONGLONG -> "wptr"
; FileSpec : LPCWSTR optional -> "wptr"
; Buffer : BYTE* optional -> "wptr"
; Size : UINT_PTR -> "wptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "dbghelp.dll"
#cfunc global SymAddSourceStreamW "SymAddSourceStreamW" sptr, int64, wstr, var, sptr
; res = SymAddSourceStreamW(hProcess, Base, FileSpec, Buffer, Size)
; hProcess : HANDLE -> "sptr"
; Base : ULONGLONG -> "int64"
; FileSpec : LPCWSTR optional -> "wstr"
; Buffer : BYTE* optional -> "var"
; Size : UINT_PTR -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; BOOL SymAddSourceStreamW(HANDLE hProcess, ULONGLONG Base, LPCWSTR FileSpec, BYTE* Buffer, UINT_PTR Size)
#uselib "dbghelp.dll"
#cfunc global SymAddSourceStreamW "SymAddSourceStreamW" intptr, int64, wstr, var, intptr
; res = SymAddSourceStreamW(hProcess, Base, FileSpec, Buffer, Size)
; hProcess : HANDLE -> "intptr"
; Base : ULONGLONG -> "int64"
; FileSpec : LPCWSTR optional -> "wstr"
; Buffer : BYTE* optional -> "var"
; Size : UINT_PTR -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procSymAddSourceStreamW = dbghelp.NewProc("SymAddSourceStreamW")
)

// hProcess (HANDLE), Base (ULONGLONG), FileSpec (LPCWSTR optional), Buffer (BYTE* optional), Size (UINT_PTR)
r1, _, err := procSymAddSourceStreamW.Call(
	uintptr(hProcess),
	uintptr(Base),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileSpec))),
	uintptr(Buffer),
	uintptr(Size),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SymAddSourceStreamW(
  hProcess: THandle;   // HANDLE
  Base: UInt64;   // ULONGLONG
  FileSpec: PWideChar;   // LPCWSTR optional
  Buffer: Pointer;   // BYTE* optional
  Size: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'dbghelp.dll' name 'SymAddSourceStreamW';
result := DllCall("dbghelp\SymAddSourceStreamW"
    , "Ptr", hProcess   ; HANDLE
    , "Int64", Base   ; ULONGLONG
    , "WStr", FileSpec   ; LPCWSTR optional
    , "Ptr", Buffer   ; BYTE* optional
    , "UPtr", Size   ; UINT_PTR
    , "Int")   ; return: BOOL
●SymAddSourceStreamW(hProcess, Base, FileSpec, Buffer, Size) = DLL("dbghelp.dll", "bool SymAddSourceStreamW(void*, qword, char*, void*, int)")
# 呼び出し: SymAddSourceStreamW(hProcess, Base, FileSpec, Buffer, Size)
# hProcess : HANDLE -> "void*"
# Base : ULONGLONG -> "qword"
# FileSpec : LPCWSTR optional -> "char*"
# Buffer : BYTE* optional -> "void*"
# Size : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。