ホーム › 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 | ロードするイメージ(実行可能ファイルまたは DLL)のファイル名。 |
| DllPath | LPCSTR | inoptional | 指定された名前が見つからない場合に、イメージを特定するために使用するパス。このパラメーターが NULL の場合、 SearchPath 関数を使用して設定された検索パスのルールが適用されます。 |
| LoadedImage | LOADED_IMAGE* | out | イメージがロードされた後に、そのイメージに関する情報を受け取る LOADED_IMAGE 構造体へのポインター。 |
| DotDll | BOOL | in | イメージ名にファイル名拡張子が含まれていない場合に使用する既定の拡張子。値が TRUE の場合は .DLL 拡張子が使用されます。値が FALSE の場合は .EXE 拡張子が使用されます。 |
| ReadOnly | BOOL | in | アクセスモード。この値が TRUE の場合、ファイルは読み取りアクセス専用としてマップされます。値が FALSE の場合、ファイルは読み取りおよび書き込みアクセス用としてマップされます。 |
戻り値の型: BOOL
公式ドキュメント
イメージをマップし、マップされたファイルからデータをプリロードします。
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
MapAndLoad 関数は、イメージをマップし、マップされたファイルからデータをプリロードします。対応する関数である UnMapAndLoad を使用して、 MapAndLoad 関数によって割り当てられたすべてのリソースを解放する必要があります。
この関数を含むすべての 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>
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 <MarshalAs(UnmanagedType.Bool)> 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)。const std = @import("std");
extern "imagehlp" fn MapAndLoad(
ImageName: [*c]const u8, // LPCSTR
DllPath: [*c]const u8, // LPCSTR optional
LoadedImage: [*c]LOADED_IMAGE, // LOADED_IMAGE* out
DotDll: i32, // BOOL
ReadOnly: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc MapAndLoad(
ImageName: cstring, # LPCSTR
DllPath: cstring, # LPCSTR optional
LoadedImage: ptr LOADED_IMAGE, # LOADED_IMAGE* out
DotDll: int32, # BOOL
ReadOnly: int32 # BOOL
): int32 {.importc: "MapAndLoad", stdcall, dynlib: "imagehlp.dll".}pragma(lib, "imagehlp");
extern(Windows)
int MapAndLoad(
const(char)* ImageName, // LPCSTR
const(char)* DllPath, // LPCSTR optional
LOADED_IMAGE* LoadedImage, // LOADED_IMAGE* out
int DotDll, // BOOL
int ReadOnly // BOOL
);ccall((:MapAndLoad, "imagehlp.dll"), stdcall, Int32,
(Cstring, Cstring, Ptr{LOADED_IMAGE}, Int32, Int32),
ImageName, DllPath, LoadedImage, DotDll, ReadOnly)
# ImageName : LPCSTR -> Cstring
# DllPath : LPCSTR optional -> Cstring
# LoadedImage : LOADED_IMAGE* out -> Ptr{LOADED_IMAGE}
# DotDll : BOOL -> Int32
# ReadOnly : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t MapAndLoad(
const char* ImageName,
const char* DllPath,
void* LoadedImage,
int32_t DotDll,
int32_t ReadOnly);
]]
local imagehlp = ffi.load("imagehlp")
-- imagehlp.MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly)
-- ImageName : LPCSTR
-- DllPath : LPCSTR optional
-- LoadedImage : LOADED_IMAGE* out
-- DotDll : BOOL
-- ReadOnly : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('imagehlp.dll');
const MapAndLoad = lib.func('__stdcall', 'MapAndLoad', 'int32_t', ['str', 'str', 'void *', 'int32_t', 'int32_t']);
// MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly)
// ImageName : LPCSTR -> 'str'
// DllPath : LPCSTR optional -> 'str'
// LoadedImage : LOADED_IMAGE* out -> 'void *'
// DotDll : BOOL -> 'int32_t'
// ReadOnly : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("imagehlp.dll", {
MapAndLoad: { parameters: ["buffer", "buffer", "pointer", "i32", "i32"], result: "i32" },
});
// lib.symbols.MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly)
// ImageName : LPCSTR -> "buffer"
// DllPath : LPCSTR optional -> "buffer"
// LoadedImage : LOADED_IMAGE* out -> "pointer"
// DotDll : BOOL -> "i32"
// ReadOnly : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MapAndLoad(
const char* ImageName,
const char* DllPath,
void* LoadedImage,
int32_t DotDll,
int32_t ReadOnly);
C, "imagehlp.dll");
// $ffi->MapAndLoad(ImageName, DllPath, LoadedImage, DotDll, ReadOnly);
// ImageName : LPCSTR
// DllPath : LPCSTR optional
// LoadedImage : LOADED_IMAGE* out
// DotDll : BOOL
// ReadOnly : BOOL
// 構造体/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 MapAndLoad(
String ImageName, // LPCSTR
String DllPath, // LPCSTR optional
Pointer LoadedImage, // LOADED_IMAGE* out
boolean DotDll, // BOOL
boolean ReadOnly // BOOL
);
}@[Link("imagehlp")]
lib Libimagehlp
fun MapAndLoad = MapAndLoad(
ImageName : UInt8*, # LPCSTR
DllPath : UInt8*, # LPCSTR optional
LoadedImage : LOADED_IMAGE*, # LOADED_IMAGE* out
DotDll : Int32, # BOOL
ReadOnly : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MapAndLoadNative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>, Int32, Int32);
typedef MapAndLoadDart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>, int, int);
final MapAndLoad = DynamicLibrary.open('imagehlp.dll')
.lookupFunction<MapAndLoadNative, MapAndLoadDart>('MapAndLoad');
// ImageName : LPCSTR -> Pointer<Utf8>
// DllPath : LPCSTR optional -> Pointer<Utf8>
// LoadedImage : LOADED_IMAGE* out -> Pointer<Void>
// DotDll : BOOL -> Int32
// ReadOnly : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MapAndLoad"
c_MapAndLoad :: CString -> CString -> Ptr () -> CInt -> CInt -> IO CInt
-- ImageName : LPCSTR -> CString
-- DllPath : LPCSTR optional -> CString
-- LoadedImage : LOADED_IMAGE* out -> Ptr ()
-- DotDll : BOOL -> CInt
-- ReadOnly : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let mapandload =
foreign "MapAndLoad"
(string @-> string @-> (ptr void) @-> int32_t @-> int32_t @-> returning int32_t)
(* ImageName : LPCSTR -> string *)
(* DllPath : LPCSTR optional -> string *)
(* LoadedImage : LOADED_IMAGE* out -> (ptr void) *)
(* DotDll : BOOL -> int32_t *)
(* ReadOnly : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library imagehlp (t "imagehlp.dll"))
(cffi:use-foreign-library imagehlp)
(cffi:defcfun ("MapAndLoad" map-and-load :convention :stdcall) :int32
(image-name :string) ; LPCSTR
(dll-path :string) ; LPCSTR optional
(loaded-image :pointer) ; LOADED_IMAGE* out
(dot-dll :int32) ; BOOL
(read-only :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MapAndLoad = Win32::API::More->new('imagehlp',
'BOOL MapAndLoad(LPCSTR ImageName, LPCSTR DllPath, LPVOID LoadedImage, BOOL DotDll, BOOL ReadOnly)');
# my $ret = $MapAndLoad->Call($ImageName, $DllPath, $LoadedImage, $DotDll, $ReadOnly);
# ImageName : LPCSTR -> LPCSTR
# DllPath : LPCSTR optional -> LPCSTR
# LoadedImage : LOADED_IMAGE* out -> LPVOID
# DotDll : BOOL -> BOOL
# ReadOnly : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f UnMapAndLoad — MapAndLoadでマップしたイメージを解放する。
使用する型