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

BindImage

関数
イメージのインポート参照をアドレスに束縛して読み込みを高速化する。
DLLimagehlp.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// imagehlp.dll
#include <windows.h>

BOOL BindImage(
    LPCSTR ImageName,
    LPCSTR DllPath,
    LPCSTR SymbolPath
);

パラメーター

名前方向説明
ImageNameLPCSTRinバインドするファイルの名前。この値には、ファイル名、部分パス、または完全パスを指定できます。
DllPathLPCSTRinImageName パラメーターで指定されたファイルを開けない場合に使用する検索パスのルート。
SymbolPathLPCSTRinファイルに対応するシンボルファイルを検索するパスのルート。

戻り値の型: BOOL

公式ドキュメント

インポートされた各関数の仮想アドレスを計算します。

戻り値

関数が成功した場合、戻り値は TRUE です。

関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

BindImage の呼び出しは、次の呼び出しと同等です: BindImageEx( 0, ImageName, DllPath, SymbolPath, NULL );

この関数を含むすべての ImageHlp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性があります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// imagehlp.dll
#include <windows.h>

BOOL BindImage(
    LPCSTR ImageName,
    LPCSTR DllPath,
    LPCSTR SymbolPath
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true, ExactSpelling = true)]
static extern bool BindImage(
    [MarshalAs(UnmanagedType.LPStr)] string ImageName,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string DllPath,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string SymbolPath   // LPCSTR
);
<DllImport("imagehlp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function BindImage(
    <MarshalAs(UnmanagedType.LPStr)> ImageName As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> DllPath As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> SymbolPath As String   ' LPCSTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ImageName : LPCSTR
' DllPath : LPCSTR
' SymbolPath : LPCSTR
Declare PtrSafe Function BindImage Lib "imagehlp" ( _
    ByVal ImageName As String, _
    ByVal DllPath As String, _
    ByVal SymbolPath As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BindImage = ctypes.windll.imagehlp.BindImage
BindImage.restype = wintypes.BOOL
BindImage.argtypes = [
    wintypes.LPCSTR,  # ImageName : LPCSTR
    wintypes.LPCSTR,  # DllPath : LPCSTR
    wintypes.LPCSTR,  # SymbolPath : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('imagehlp.dll')
BindImage = Fiddle::Function.new(
  lib['BindImage'],
  [
    Fiddle::TYPE_VOIDP,  # ImageName : LPCSTR
    Fiddle::TYPE_VOIDP,  # DllPath : LPCSTR
    Fiddle::TYPE_VOIDP,  # SymbolPath : LPCSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "imagehlp")]
extern "system" {
    fn BindImage(
        ImageName: *const u8,  // LPCSTR
        DllPath: *const u8,  // LPCSTR
        SymbolPath: *const u8  // LPCSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true)]
public static extern bool BindImage([MarshalAs(UnmanagedType.LPStr)] string ImageName, [MarshalAs(UnmanagedType.LPStr)] string DllPath, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_BindImage' -Namespace Win32 -PassThru
# $api::BindImage(ImageName, DllPath, SymbolPath)
#uselib "imagehlp.dll"
#func global BindImage "BindImage" sptr, sptr, sptr
; BindImage ImageName, DllPath, SymbolPath   ; 戻り値は stat
; ImageName : LPCSTR -> "sptr"
; DllPath : LPCSTR -> "sptr"
; SymbolPath : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "imagehlp.dll"
#cfunc global BindImage "BindImage" str, str, str
; res = BindImage(ImageName, DllPath, SymbolPath)
; ImageName : LPCSTR -> "str"
; DllPath : LPCSTR -> "str"
; SymbolPath : LPCSTR -> "str"
; BOOL BindImage(LPCSTR ImageName, LPCSTR DllPath, LPCSTR SymbolPath)
#uselib "imagehlp.dll"
#cfunc global BindImage "BindImage" str, str, str
; res = BindImage(ImageName, DllPath, SymbolPath)
; ImageName : LPCSTR -> "str"
; DllPath : LPCSTR -> "str"
; SymbolPath : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
	procBindImage = imagehlp.NewProc("BindImage")
)

// ImageName (LPCSTR), DllPath (LPCSTR), SymbolPath (LPCSTR)
r1, _, err := procBindImage.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(ImageName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DllPath))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SymbolPath))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function BindImage(
  ImageName: PAnsiChar;   // LPCSTR
  DllPath: PAnsiChar;   // LPCSTR
  SymbolPath: PAnsiChar   // LPCSTR
): BOOL; stdcall;
  external 'imagehlp.dll' name 'BindImage';
result := DllCall("imagehlp\BindImage"
    , "AStr", ImageName   ; LPCSTR
    , "AStr", DllPath   ; LPCSTR
    , "AStr", SymbolPath   ; LPCSTR
    , "Int")   ; return: BOOL
●BindImage(ImageName, DllPath, SymbolPath) = DLL("imagehlp.dll", "bool BindImage(char*, char*, char*)")
# 呼び出し: BindImage(ImageName, DllPath, SymbolPath)
# ImageName : LPCSTR -> "char*"
# DllPath : LPCSTR -> "char*"
# SymbolPath : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "imagehlp" fn BindImage(
    ImageName: [*c]const u8, // LPCSTR
    DllPath: [*c]const u8, // LPCSTR
    SymbolPath: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) i32;
proc BindImage(
    ImageName: cstring,  # LPCSTR
    DllPath: cstring,  # LPCSTR
    SymbolPath: cstring  # LPCSTR
): int32 {.importc: "BindImage", stdcall, dynlib: "imagehlp.dll".}
pragma(lib, "imagehlp");
extern(Windows)
int BindImage(
    const(char)* ImageName,   // LPCSTR
    const(char)* DllPath,   // LPCSTR
    const(char)* SymbolPath   // LPCSTR
);
ccall((:BindImage, "imagehlp.dll"), stdcall, Int32,
      (Cstring, Cstring, Cstring),
      ImageName, DllPath, SymbolPath)
# ImageName : LPCSTR -> Cstring
# DllPath : LPCSTR -> Cstring
# SymbolPath : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t BindImage(
    const char* ImageName,
    const char* DllPath,
    const char* SymbolPath);
]]
local imagehlp = ffi.load("imagehlp")
-- imagehlp.BindImage(ImageName, DllPath, SymbolPath)
-- ImageName : LPCSTR
-- DllPath : LPCSTR
-- SymbolPath : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('imagehlp.dll');
const BindImage = lib.func('__stdcall', 'BindImage', 'int32_t', ['str', 'str', 'str']);
// BindImage(ImageName, DllPath, SymbolPath)
// ImageName : LPCSTR -> 'str'
// DllPath : LPCSTR -> 'str'
// SymbolPath : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("imagehlp.dll", {
  BindImage: { parameters: ["buffer", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.BindImage(ImageName, DllPath, SymbolPath)
// ImageName : LPCSTR -> "buffer"
// DllPath : LPCSTR -> "buffer"
// SymbolPath : LPCSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t BindImage(
    const char* ImageName,
    const char* DllPath,
    const char* SymbolPath);
C, "imagehlp.dll");
// $ffi->BindImage(ImageName, DllPath, SymbolPath);
// ImageName : LPCSTR
// DllPath : LPCSTR
// SymbolPath : LPCSTR
// 構造体/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 Imagehlp extends StdCallLibrary {
    Imagehlp INSTANCE = Native.load("imagehlp", Imagehlp.class);
    boolean BindImage(
        String ImageName,   // LPCSTR
        String DllPath,   // LPCSTR
        String SymbolPath   // LPCSTR
    );
}
@[Link("imagehlp")]
lib Libimagehlp
  fun BindImage = BindImage(
    ImageName : UInt8*,   # LPCSTR
    DllPath : UInt8*,   # LPCSTR
    SymbolPath : UInt8*   # LPCSTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef BindImageNative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
typedef BindImageDart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
final BindImage = DynamicLibrary.open('imagehlp.dll')
    .lookupFunction<BindImageNative, BindImageDart>('BindImage');
// ImageName : LPCSTR -> Pointer<Utf8>
// DllPath : LPCSTR -> Pointer<Utf8>
// SymbolPath : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function BindImage(
  ImageName: PAnsiChar;   // LPCSTR
  DllPath: PAnsiChar;   // LPCSTR
  SymbolPath: PAnsiChar   // LPCSTR
): BOOL; stdcall;
  external 'imagehlp.dll' name 'BindImage';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BindImage"
  c_BindImage :: CString -> CString -> CString -> IO CInt
-- ImageName : LPCSTR -> CString
-- DllPath : LPCSTR -> CString
-- SymbolPath : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let bindimage =
  foreign "BindImage"
    (string @-> string @-> string @-> returning int32_t)
(* ImageName : LPCSTR -> string *)
(* DllPath : LPCSTR -> string *)
(* SymbolPath : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library imagehlp (t "imagehlp.dll"))
(cffi:use-foreign-library imagehlp)

(cffi:defcfun ("BindImage" bind-image :convention :stdcall) :int32
  (image-name :string)   ; LPCSTR
  (dll-path :string)   ; LPCSTR
  (symbol-path :string))   ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BindImage = Win32::API::More->new('imagehlp',
    'BOOL BindImage(LPCSTR ImageName, LPCSTR DllPath, LPCSTR SymbolPath)');
# my $ret = $BindImage->Call($ImageName, $DllPath, $SymbolPath);
# ImageName : LPCSTR -> LPCSTR
# DllPath : LPCSTR -> LPCSTR
# SymbolPath : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API