ホーム › System.Diagnostics.Debug › FindExecutableImage
FindExecutableImage
関数シンボルパスから実行イメージファイルを検索する。
シグネチャ
// dbghelp.dll
#include <windows.h>
HANDLE FindExecutableImage(
LPCSTR FileName,
LPCSTR SymbolPath,
LPSTR ImageFilePath
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| FileName | LPCSTR | in |
| SymbolPath | LPCSTR | in |
| ImageFilePath | LPSTR | out |
戻り値の型: HANDLE
各言語での呼び出し定義
// dbghelp.dll
#include <windows.h>
HANDLE FindExecutableImage(
LPCSTR FileName,
LPCSTR SymbolPath,
LPSTR ImageFilePath
);[DllImport("dbghelp.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindExecutableImage(
[MarshalAs(UnmanagedType.LPStr)] string FileName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string SymbolPath, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder ImageFilePath // LPSTR out
);<DllImport("dbghelp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindExecutableImage(
<MarshalAs(UnmanagedType.LPStr)> FileName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> SymbolPath As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> ImageFilePath As System.Text.StringBuilder ' LPSTR out
) As IntPtr
End Function' FileName : LPCSTR
' SymbolPath : LPCSTR
' ImageFilePath : LPSTR out
Declare PtrSafe Function FindExecutableImage Lib "dbghelp" ( _
ByVal FileName As String, _
ByVal SymbolPath As String, _
ByVal ImageFilePath As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FindExecutableImage = ctypes.windll.dbghelp.FindExecutableImage
FindExecutableImage.restype = ctypes.c_void_p
FindExecutableImage.argtypes = [
wintypes.LPCSTR, # FileName : LPCSTR
wintypes.LPCSTR, # SymbolPath : LPCSTR
wintypes.LPSTR, # ImageFilePath : LPSTR out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dbghelp.dll')
FindExecutableImage = Fiddle::Function.new(
lib['FindExecutableImage'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCSTR
Fiddle::TYPE_VOIDP, # SymbolPath : LPCSTR
Fiddle::TYPE_VOIDP, # ImageFilePath : LPSTR out
],
Fiddle::TYPE_VOIDP)#[link(name = "dbghelp")]
extern "system" {
fn FindExecutableImage(
FileName: *const u8, // LPCSTR
SymbolPath: *const u8, // LPCSTR
ImageFilePath: *mut u8 // LPSTR out
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("dbghelp.dll", SetLastError = true)]
public static extern IntPtr FindExecutableImage([MarshalAs(UnmanagedType.LPStr)] string FileName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder ImageFilePath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_FindExecutableImage' -Namespace Win32 -PassThru
# $api::FindExecutableImage(FileName, SymbolPath, ImageFilePath)#uselib "dbghelp.dll"
#func global FindExecutableImage "FindExecutableImage" sptr, sptr, sptr
; FindExecutableImage FileName, SymbolPath, varptr(ImageFilePath) ; 戻り値は stat
; FileName : LPCSTR -> "sptr"
; SymbolPath : LPCSTR -> "sptr"
; ImageFilePath : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "dbghelp.dll" #cfunc global FindExecutableImage "FindExecutableImage" str, str, var ; res = FindExecutableImage(FileName, SymbolPath, ImageFilePath) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; ImageFilePath : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dbghelp.dll" #cfunc global FindExecutableImage "FindExecutableImage" str, str, sptr ; res = FindExecutableImage(FileName, SymbolPath, varptr(ImageFilePath)) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; ImageFilePath : LPSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HANDLE FindExecutableImage(LPCSTR FileName, LPCSTR SymbolPath, LPSTR ImageFilePath) #uselib "dbghelp.dll" #cfunc global FindExecutableImage "FindExecutableImage" str, str, var ; res = FindExecutableImage(FileName, SymbolPath, ImageFilePath) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; ImageFilePath : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HANDLE FindExecutableImage(LPCSTR FileName, LPCSTR SymbolPath, LPSTR ImageFilePath) #uselib "dbghelp.dll" #cfunc global FindExecutableImage "FindExecutableImage" str, str, intptr ; res = FindExecutableImage(FileName, SymbolPath, varptr(ImageFilePath)) ; FileName : LPCSTR -> "str" ; SymbolPath : LPCSTR -> "str" ; ImageFilePath : LPSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
procFindExecutableImage = dbghelp.NewProc("FindExecutableImage")
)
// FileName (LPCSTR), SymbolPath (LPCSTR), ImageFilePath (LPSTR out)
r1, _, err := procFindExecutableImage.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(FileName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(SymbolPath))),
uintptr(ImageFilePath),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction FindExecutableImage(
FileName: PAnsiChar; // LPCSTR
SymbolPath: PAnsiChar; // LPCSTR
ImageFilePath: PAnsiChar // LPSTR out
): THandle; stdcall;
external 'dbghelp.dll' name 'FindExecutableImage';result := DllCall("dbghelp\FindExecutableImage"
, "AStr", FileName ; LPCSTR
, "AStr", SymbolPath ; LPCSTR
, "Ptr", ImageFilePath ; LPSTR out
, "Ptr") ; return: HANDLE●FindExecutableImage(FileName, SymbolPath, ImageFilePath) = DLL("dbghelp.dll", "void* FindExecutableImage(char*, char*, char*)")
# 呼び出し: FindExecutableImage(FileName, SymbolPath, ImageFilePath)
# FileName : LPCSTR -> "char*"
# SymbolPath : LPCSTR -> "char*"
# ImageFilePath : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。