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

SymSetSearchPathW

関数
シンボル検索パスを設定する(Unicode版)。
DLLdbghelp.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL SymSetSearchPathW(
    HANDLE hProcess,
    LPCWSTR SearchPathA   // optional
);

パラメーター

名前方向
hProcessHANDLEin
SearchPathALPCWSTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SymSetSearchPathW(
    HANDLE hProcess,
    LPCWSTR SearchPathA   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SymSetSearchPathW(
    IntPtr hProcess,   // HANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string SearchPathA   // LPCWSTR optional
);
<DllImport("dbghelp.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymSetSearchPathW(
    hProcess As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.LPWStr)> SearchPathA As String   ' LPCWSTR optional
) As Boolean
End Function
' hProcess : HANDLE
' SearchPathA : LPCWSTR optional
Declare PtrSafe Function SymSetSearchPathW Lib "dbghelp" ( _
    ByVal hProcess As LongPtr, _
    ByVal SearchPathA 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

SymSetSearchPathW = ctypes.windll.dbghelp.SymSetSearchPathW
SymSetSearchPathW.restype = wintypes.BOOL
SymSetSearchPathW.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    wintypes.LPCWSTR,  # SearchPathA : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
SymSetSearchPathW = Fiddle::Function.new(
  lib['SymSetSearchPathW'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    Fiddle::TYPE_VOIDP,  # SearchPathA : LPCWSTR optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "dbghelp")]
extern "system" {
    fn SymSetSearchPathW(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        SearchPathA: *const u16  // LPCWSTR 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 SymSetSearchPathW(IntPtr hProcess, [MarshalAs(UnmanagedType.LPWStr)] string SearchPathA);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymSetSearchPathW' -Namespace Win32 -PassThru
# $api::SymSetSearchPathW(hProcess, SearchPathA)
#uselib "dbghelp.dll"
#func global SymSetSearchPathW "SymSetSearchPathW" wptr, wptr
; SymSetSearchPathW hProcess, SearchPathA   ; 戻り値は stat
; hProcess : HANDLE -> "wptr"
; SearchPathA : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "dbghelp.dll"
#cfunc global SymSetSearchPathW "SymSetSearchPathW" sptr, wstr
; res = SymSetSearchPathW(hProcess, SearchPathA)
; hProcess : HANDLE -> "sptr"
; SearchPathA : LPCWSTR optional -> "wstr"
; BOOL SymSetSearchPathW(HANDLE hProcess, LPCWSTR SearchPathA)
#uselib "dbghelp.dll"
#cfunc global SymSetSearchPathW "SymSetSearchPathW" intptr, wstr
; res = SymSetSearchPathW(hProcess, SearchPathA)
; hProcess : HANDLE -> "intptr"
; SearchPathA : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procSymSetSearchPathW = dbghelp.NewProc("SymSetSearchPathW")
)

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