ホーム › System.Diagnostics.Debug › FindExecutableImage
FindExecutableImage
関数シンボルパスから実行イメージファイルを検索する。
シグネチャ
// dbghelp.dll
#include <windows.h>
HANDLE FindExecutableImage(
LPCSTR FileName,
LPCSTR SymbolPath,
LPSTR ImageFilePath
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCSTR | in | 場所を特定するシンボルファイルの名前。このパラメーターには部分的なパスを指定できます。 |
| SymbolPath | LPCSTR | in | シンボルファイルが配置されているパス。セミコロンで区切って複数のパスを指定できます。シンボルパスを取得するには、 SymGetSearchPath 関数を使用します。 |
| ImageFilePath | LPSTR | out | 実行可能ファイルのフルパスを受け取るバッファーへのポインター。このバッファーは少なくとも MAX_PATH+1 文字分の大きさが必要です。 |
戻り値の型: HANDLE
公式ドキュメント
実行可能ファイルの場所を特定します。
戻り値
関数が成功した場合、戻り値は実行可能ファイルへの開かれたハンドルです。
関数が失敗した場合、戻り値は NULL です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
FindExecutableImage 関数は、1 回の関数呼び出しで複数の異なるディレクトリから実行可能ファイルの場所を特定できるように用意されています。SymbolPath パラメーターには複数のパスを指定でき、各パスはセミコロン (;) で区切ります。複数のパスを指定した場合、関数は各ディレクトリツリーを順に検索して実行可能ファイルを探します。ファイルが見つかると検索は停止します。したがって、SymbolPath にはパスを正しい順序で指定してください。
この関数を含むすべての DbgHelp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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)。const std = @import("std");
extern "dbghelp" fn FindExecutableImage(
FileName: [*c]const u8, // LPCSTR
SymbolPath: [*c]const u8, // LPCSTR
ImageFilePath: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc FindExecutableImage(
FileName: cstring, # LPCSTR
SymbolPath: cstring, # LPCSTR
ImageFilePath: ptr char # LPSTR out
): pointer {.importc: "FindExecutableImage", stdcall, dynlib: "dbghelp.dll".}pragma(lib, "dbghelp");
extern(Windows)
void* FindExecutableImage(
const(char)* FileName, // LPCSTR
const(char)* SymbolPath, // LPCSTR
char* ImageFilePath // LPSTR out
);ccall((:FindExecutableImage, "dbghelp.dll"), stdcall, Ptr{Cvoid},
(Cstring, Cstring, Ptr{UInt8}),
FileName, SymbolPath, ImageFilePath)
# FileName : LPCSTR -> Cstring
# SymbolPath : LPCSTR -> Cstring
# ImageFilePath : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* FindExecutableImage(
const char* FileName,
const char* SymbolPath,
char* ImageFilePath);
]]
local dbghelp = ffi.load("dbghelp")
-- dbghelp.FindExecutableImage(FileName, SymbolPath, ImageFilePath)
-- FileName : LPCSTR
-- SymbolPath : LPCSTR
-- ImageFilePath : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('dbghelp.dll');
const FindExecutableImage = lib.func('__stdcall', 'FindExecutableImage', 'void *', ['str', 'str', 'char *']);
// FindExecutableImage(FileName, SymbolPath, ImageFilePath)
// FileName : LPCSTR -> 'str'
// SymbolPath : LPCSTR -> 'str'
// ImageFilePath : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("dbghelp.dll", {
FindExecutableImage: { parameters: ["buffer", "buffer", "buffer"], result: "pointer" },
});
// lib.symbols.FindExecutableImage(FileName, SymbolPath, ImageFilePath)
// FileName : LPCSTR -> "buffer"
// SymbolPath : LPCSTR -> "buffer"
// ImageFilePath : LPSTR out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* FindExecutableImage(
const char* FileName,
const char* SymbolPath,
char* ImageFilePath);
C, "dbghelp.dll");
// $ffi->FindExecutableImage(FileName, SymbolPath, ImageFilePath);
// FileName : LPCSTR
// SymbolPath : LPCSTR
// ImageFilePath : LPSTR out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Dbghelp extends StdCallLibrary {
Dbghelp INSTANCE = Native.load("dbghelp", Dbghelp.class);
Pointer FindExecutableImage(
String FileName, // LPCSTR
String SymbolPath, // LPCSTR
byte[] ImageFilePath // LPSTR out
);
}@[Link("dbghelp")]
lib Libdbghelp
fun FindExecutableImage = FindExecutableImage(
FileName : UInt8*, # LPCSTR
SymbolPath : UInt8*, # LPCSTR
ImageFilePath : UInt8* # LPSTR out
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef FindExecutableImageNative = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
typedef FindExecutableImageDart = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
final FindExecutableImage = DynamicLibrary.open('dbghelp.dll')
.lookupFunction<FindExecutableImageNative, FindExecutableImageDart>('FindExecutableImage');
// FileName : LPCSTR -> Pointer<Utf8>
// SymbolPath : LPCSTR -> Pointer<Utf8>
// ImageFilePath : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function FindExecutableImage(
FileName: PAnsiChar; // LPCSTR
SymbolPath: PAnsiChar; // LPCSTR
ImageFilePath: PAnsiChar // LPSTR out
): THandle; stdcall;
external 'dbghelp.dll' name 'FindExecutableImage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "FindExecutableImage"
c_FindExecutableImage :: CString -> CString -> CString -> IO (Ptr ())
-- FileName : LPCSTR -> CString
-- SymbolPath : LPCSTR -> CString
-- ImageFilePath : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let findexecutableimage =
foreign "FindExecutableImage"
(string @-> string @-> string @-> returning (ptr void))
(* FileName : LPCSTR -> string *)
(* SymbolPath : LPCSTR -> string *)
(* ImageFilePath : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dbghelp (t "dbghelp.dll"))
(cffi:use-foreign-library dbghelp)
(cffi:defcfun ("FindExecutableImage" find-executable-image :convention :stdcall) :pointer
(file-name :string) ; LPCSTR
(symbol-path :string) ; LPCSTR
(image-file-path :pointer)) ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $FindExecutableImage = Win32::API::More->new('dbghelp',
'HANDLE FindExecutableImage(LPCSTR FileName, LPCSTR SymbolPath, LPSTR ImageFilePath)');
# my $ret = $FindExecutableImage->Call($FileName, $SymbolPath, $ImageFilePath);
# FileName : LPCSTR -> LPCSTR
# SymbolPath : LPCSTR -> LPCSTR
# ImageFilePath : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f FindExecutableImageExW — コールバック付きで実行イメージファイルを検索する拡張版である。
公式の関連項目
- f SymGetSearchPathW — シンボル検索パスを取得する(Unicode版)。