ホーム › System.Diagnostics.Debug › MapAndLoad
MapAndLoad
関数実行イメージをマップしロード済みイメージ構造体を初期化する。
シグネチャ
// imagehlp.dll
#include <windows.h>
BOOL MapAndLoad(
LPCSTR ImageName,
LPCSTR DllPath, // optional
LOADED_IMAGE* LoadedImage,
BOOL DotDll,
BOOL ReadOnly
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ImageName | LPCSTR | in |
| DllPath | LPCSTR | inoptional |
| LoadedImage | LOADED_IMAGE* | out |
| DotDll | BOOL | in |
| ReadOnly | BOOL | in |
戻り値の型: BOOL
各言語での呼び出し定義
// imagehlp.dll
#include <windows.h>
BOOL MapAndLoad(
LPCSTR ImageName,
LPCSTR DllPath, // optional
LOADED_IMAGE* LoadedImage,
BOOL DotDll,
BOOL ReadOnly
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("imagehlp.dll", SetLastError = true, ExactSpelling = true)]
static extern bool MapAndLoad(
[MarshalAs(UnmanagedType.LPStr)] string ImageName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string DllPath, // LPCSTR optional
IntPtr LoadedImage, // LOADED_IMAGE* out
bool DotDll, // BOOL
bool ReadOnly // BOOL
);<DllImport("imagehlp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MapAndLoad(
<MarshalAs(UnmanagedType.LPStr)> ImageName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> DllPath As String, ' LPCSTR optional
LoadedImage As IntPtr, ' LOADED_IMAGE* out
DotDll As Boolean, ' BOOL
[ReadOnly] As Boolean ' BOOL
) As Boolean
End Function' ImageName : LPCSTR
' DllPath : LPCSTR optional
' LoadedImage : LOADED_IMAGE* out
' DotDll : BOOL
' ReadOnly : BOOL
Declare PtrSafe Function MapAndLoad Lib "imagehlp" ( _
ByVal ImageName As String, _
ByVal DllPath As String, _
ByVal LoadedImage As LongPtr, _
ByVal DotDll As Long, _
ByVal ReadOnly As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MapAndLoad = ctypes.windll.imagehlp.MapAndLoad
MapAndLoad.restype = wintypes.BOOL
MapAndLoad.argtypes = [
wintypes.LPCSTR, # ImageName : LPCSTR
wintypes.LPCSTR, # DllPath : LPCSTR optional
ctypes.c_void_p, # LoadedImage : LOADED_IMAGE* out
wintypes.BOOL, # DotDll : BOOL
wintypes.BOOL, # ReadOnly : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('imagehlp.dll')
MapAndLoad = Fiddle::Function.new(
lib['MapAndLoad'],
[
Fiddle::TYPE_VOIDP, # ImageName : LPCSTR
Fiddle::TYPE_VOIDP, # DllPath : LPCSTR optional
Fiddle::TYPE_VOIDP, # LoadedImage : LOADED_IMAGE* out
Fiddle::TYPE_INT, # DotDll : BOOL
Fiddle::TYPE_INT, # ReadOnly : BOOL
],
Fiddle::TYPE_INT)#[link(name = "imagehlp")]
extern "system" {
fn MapAndLoad(
ImageName: *const u8, // LPCSTR
DllPath: *const u8, // LPCSTR optional
LoadedImage: *mut LOADED_IMAGE, // LOADED_IMAGE* out
DotDll: i32, // BOOL
ReadOnly: i32 // BOOL
) -> 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 MapAndLoad([MarshalAs(UnmanagedType.LPStr)] string ImageName, [MarshalAs(UnmanagedType.LPStr)] string DllPath, IntPtr LoadedImage, bool DotDll, bool ReadOnly);
"@
$api = Add-Type -MemberDefinition $sig -Name 'imagehlp_MapAndLoad' -Namespace Win32 -PassThru
# $api::MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly)#uselib "imagehlp.dll"
#func global MapAndLoad "MapAndLoad" sptr, sptr, sptr, sptr, sptr
; MapAndLoad ImageName, DllPath, varptr(LoadedImage), DotDll, ReadOnly ; 戻り値は stat
; ImageName : LPCSTR -> "sptr"
; DllPath : LPCSTR optional -> "sptr"
; LoadedImage : LOADED_IMAGE* out -> "sptr"
; DotDll : BOOL -> "sptr"
; ReadOnly : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "imagehlp.dll" #cfunc global MapAndLoad "MapAndLoad" str, str, var, int, int ; res = MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly) ; ImageName : LPCSTR -> "str" ; DllPath : LPCSTR optional -> "str" ; LoadedImage : LOADED_IMAGE* out -> "var" ; DotDll : BOOL -> "int" ; ReadOnly : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "imagehlp.dll" #cfunc global MapAndLoad "MapAndLoad" str, str, sptr, int, int ; res = MapAndLoad(ImageName, DllPath, varptr(LoadedImage), DotDll, ReadOnly) ; ImageName : LPCSTR -> "str" ; DllPath : LPCSTR optional -> "str" ; LoadedImage : LOADED_IMAGE* out -> "sptr" ; DotDll : BOOL -> "int" ; ReadOnly : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL MapAndLoad(LPCSTR ImageName, LPCSTR DllPath, LOADED_IMAGE* LoadedImage, BOOL DotDll, BOOL ReadOnly) #uselib "imagehlp.dll" #cfunc global MapAndLoad "MapAndLoad" str, str, var, int, int ; res = MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly) ; ImageName : LPCSTR -> "str" ; DllPath : LPCSTR optional -> "str" ; LoadedImage : LOADED_IMAGE* out -> "var" ; DotDll : BOOL -> "int" ; ReadOnly : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL MapAndLoad(LPCSTR ImageName, LPCSTR DllPath, LOADED_IMAGE* LoadedImage, BOOL DotDll, BOOL ReadOnly) #uselib "imagehlp.dll" #cfunc global MapAndLoad "MapAndLoad" str, str, intptr, int, int ; res = MapAndLoad(ImageName, DllPath, varptr(LoadedImage), DotDll, ReadOnly) ; ImageName : LPCSTR -> "str" ; DllPath : LPCSTR optional -> "str" ; LoadedImage : LOADED_IMAGE* out -> "intptr" ; DotDll : BOOL -> "int" ; ReadOnly : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
imagehlp = windows.NewLazySystemDLL("imagehlp.dll")
procMapAndLoad = imagehlp.NewProc("MapAndLoad")
)
// ImageName (LPCSTR), DllPath (LPCSTR optional), LoadedImage (LOADED_IMAGE* out), DotDll (BOOL), ReadOnly (BOOL)
r1, _, err := procMapAndLoad.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(ImageName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(DllPath))),
uintptr(LoadedImage),
uintptr(DotDll),
uintptr(ReadOnly),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction MapAndLoad(
ImageName: PAnsiChar; // LPCSTR
DllPath: PAnsiChar; // LPCSTR optional
LoadedImage: Pointer; // LOADED_IMAGE* out
DotDll: BOOL; // BOOL
ReadOnly: BOOL // BOOL
): BOOL; stdcall;
external 'imagehlp.dll' name 'MapAndLoad';result := DllCall("imagehlp\MapAndLoad"
, "AStr", ImageName ; LPCSTR
, "AStr", DllPath ; LPCSTR optional
, "Ptr", LoadedImage ; LOADED_IMAGE* out
, "Int", DotDll ; BOOL
, "Int", ReadOnly ; BOOL
, "Int") ; return: BOOL●MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly) = DLL("imagehlp.dll", "bool MapAndLoad(char*, char*, void*, bool, bool)")
# 呼び出し: MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly)
# ImageName : LPCSTR -> "char*"
# DllPath : LPCSTR optional -> "char*"
# LoadedImage : LOADED_IMAGE* out -> "void*"
# DotDll : BOOL -> "bool"
# ReadOnly : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。