ホーム › System.Diagnostics.Debug › ImageLoad
ImageLoad
関数DLLイメージをデバッグ用にメモリへ読み込む。
シグネチャ
// imagehlp.dll
#include <windows.h>
LOADED_IMAGE* ImageLoad(
LPCSTR DllName,
LPCSTR DllPath // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DllName | LPCSTR | in | イメージの名前です。 |
| DllPath | LPCSTR | inoptional | 指定された名前でイメージが見つからない場合に、イメージの位置を特定するために使用するパスです。NULL を指定した場合は、 SearchPath 関数に定められた検索パスのルールが適用されます。 |
戻り値の型: LOADED_IMAGE*
公式ドキュメント
ロードされた DLL のリストを管理します。
戻り値
関数が成功した場合、戻り値は LOADED_IMAGE 構造体へのポインターです。
関数が失敗した場合、戻り値は NULL です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
ImageLoad 関数は、ロードされた DLL のリストを管理するために使用します。イメージが既にロードされている場合は、以前の LOADED_IMAGE が返されます。それ以外の場合は、新しいイメージがリストに追加されます。
LOADED_IMAGE 構造体は、 ImageUnload 関数によって解放する必要があります。
この関数を含むすべての ImageHlp 関数はシングルスレッドです。そのため、複数のスレッドからこの関数を呼び出すと、予期しない動作やメモリ破損が発生する可能性が高くなります。これを回避するには、複数のスレッドからこの関数への同時呼び出しをすべて同期する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// imagehlp.dll
#include <windows.h>
LOADED_IMAGE* ImageLoad(
LPCSTR DllName,
LPCSTR DllPath // optional
);[DllImport("imagehlp.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr ImageLoad(
[MarshalAs(UnmanagedType.LPStr)] string DllName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string DllPath // LPCSTR optional
);<DllImport("imagehlp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ImageLoad(
<MarshalAs(UnmanagedType.LPStr)> DllName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> DllPath As String ' LPCSTR optional
) As IntPtr
End Function' DllName : LPCSTR
' DllPath : LPCSTR optional
Declare PtrSafe Function ImageLoad Lib "imagehlp" ( _
ByVal DllName As String, _
ByVal DllPath As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ImageLoad = ctypes.windll.imagehlp.ImageLoad
ImageLoad.restype = ctypes.c_void_p
ImageLoad.argtypes = [
wintypes.LPCSTR, # DllName : LPCSTR
wintypes.LPCSTR, # DllPath : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('imagehlp.dll')
ImageLoad = Fiddle::Function.new(
lib['ImageLoad'],
[
Fiddle::TYPE_VOIDP, # DllName : LPCSTR
Fiddle::TYPE_VOIDP, # DllPath : LPCSTR optional
],
Fiddle::TYPE_VOIDP)#[link(name = "imagehlp")]
extern "system" {
fn ImageLoad(
DllName: *const u8, // LPCSTR
DllPath: *const u8 // LPCSTR optional
) -> *mut LOADED_IMAGE;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("imagehlp.dll", SetLastError = true)]
public static extern IntPtr ImageLoad([MarshalAs(UnmanagedType.LPStr)] string DllName, [MarshalAs(UnmanagedType.LPStr)] string DllPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_ImageLoad' -Namespace Win32 -PassThru
# $api::ImageLoad(DllName, DllPath)#uselib "imagehlp.dll"
#func global ImageLoad "ImageLoad" sptr, sptr
; ImageLoad DllName, DllPath ; 戻り値は stat
; DllName : LPCSTR -> "sptr"
; DllPath : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "imagehlp.dll"
#cfunc global ImageLoad "ImageLoad" str, str
; res = ImageLoad(DllName, DllPath)
; DllName : LPCSTR -> "str"
; DllPath : LPCSTR optional -> "str"; LOADED_IMAGE* ImageLoad(LPCSTR DllName, LPCSTR DllPath)
#uselib "imagehlp.dll"
#cfunc global ImageLoad "ImageLoad" str, str
; res = ImageLoad(DllName, DllPath)
; DllName : LPCSTR -> "str"
; DllPath : LPCSTR optional -> "str"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
procImageLoad = imagehlp.NewProc("ImageLoad")
)
// DllName (LPCSTR), DllPath (LPCSTR optional)
r1, _, err := procImageLoad.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(DllName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(DllPath))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LOADED_IMAGE*function ImageLoad(
DllName: PAnsiChar; // LPCSTR
DllPath: PAnsiChar // LPCSTR optional
): Pointer; stdcall;
external 'imagehlp.dll' name 'ImageLoad';result := DllCall("imagehlp\ImageLoad"
, "AStr", DllName ; LPCSTR
, "AStr", DllPath ; LPCSTR optional
, "Ptr") ; return: LOADED_IMAGE*●ImageLoad(DllName, DllPath) = DLL("imagehlp.dll", "void* ImageLoad(char*, char*)")
# 呼び出し: ImageLoad(DllName, DllPath)
# DllName : LPCSTR -> "char*"
# DllPath : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "imagehlp" fn ImageLoad(
DllName: [*c]const u8, // LPCSTR
DllPath: [*c]const u8 // LPCSTR optional
) callconv(std.os.windows.WINAPI) [*c]LOADED_IMAGE;proc ImageLoad(
DllName: cstring, # LPCSTR
DllPath: cstring # LPCSTR optional
): ptr LOADED_IMAGE {.importc: "ImageLoad", stdcall, dynlib: "imagehlp.dll".}pragma(lib, "imagehlp");
extern(Windows)
LOADED_IMAGE* ImageLoad(
const(char)* DllName, // LPCSTR
const(char)* DllPath // LPCSTR optional
);ccall((:ImageLoad, "imagehlp.dll"), stdcall, Ptr{LOADED_IMAGE},
(Cstring, Cstring),
DllName, DllPath)
# DllName : LPCSTR -> Cstring
# DllPath : LPCSTR optional -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* ImageLoad(
const char* DllName,
const char* DllPath);
]]
local imagehlp = ffi.load("imagehlp")
-- imagehlp.ImageLoad(DllName, DllPath)
-- DllName : LPCSTR
-- DllPath : LPCSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('imagehlp.dll');
const ImageLoad = lib.func('__stdcall', 'ImageLoad', 'void *', ['str', 'str']);
// ImageLoad(DllName, DllPath)
// DllName : LPCSTR -> 'str'
// DllPath : LPCSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("imagehlp.dll", {
ImageLoad: { parameters: ["buffer", "buffer"], result: "pointer" },
});
// lib.symbols.ImageLoad(DllName, DllPath)
// DllName : LPCSTR -> "buffer"
// DllPath : LPCSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* ImageLoad(
const char* DllName,
const char* DllPath);
C, "imagehlp.dll");
// $ffi->ImageLoad(DllName, DllPath);
// DllName : LPCSTR
// DllPath : LPCSTR optional
// 構造体/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);
Pointer ImageLoad(
String DllName, // LPCSTR
String DllPath // LPCSTR optional
);
}@[Link("imagehlp")]
lib Libimagehlp
fun ImageLoad = ImageLoad(
DllName : UInt8*, # LPCSTR
DllPath : UInt8* # LPCSTR optional
) : LOADED_IMAGE*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ImageLoadNative = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>);
typedef ImageLoadDart = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>);
final ImageLoad = DynamicLibrary.open('imagehlp.dll')
.lookupFunction<ImageLoadNative, ImageLoadDart>('ImageLoad');
// DllName : LPCSTR -> Pointer<Utf8>
// DllPath : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ImageLoad(
DllName: PAnsiChar; // LPCSTR
DllPath: PAnsiChar // LPCSTR optional
): Pointer; stdcall;
external 'imagehlp.dll' name 'ImageLoad';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ImageLoad"
c_ImageLoad :: CString -> CString -> IO (Ptr ())
-- DllName : LPCSTR -> CString
-- DllPath : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let imageload =
foreign "ImageLoad"
(string @-> string @-> returning (ptr void))
(* DllName : LPCSTR -> string *)
(* DllPath : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library imagehlp (t "imagehlp.dll"))
(cffi:use-foreign-library imagehlp)
(cffi:defcfun ("ImageLoad" image-load :convention :stdcall) :pointer
(dll-name :string) ; LPCSTR
(dll-path :string)) ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ImageLoad = Win32::API::More->new('imagehlp',
'LPVOID ImageLoad(LPCSTR DllName, LPCSTR DllPath)');
# my $ret = $ImageLoad->Call($DllName, $DllPath);
# DllName : LPCSTR -> LPCSTR
# DllPath : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f ImageUnload — ImageLoadで読み込んだイメージを解放する。
使用する型