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

RtlPcToFileHeader

関数
指定したPC値を含むイメージのベースアドレスを取得する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

void* RtlPcToFileHeader(
    void* PcValue,
    void** BaseOfImage
);

パラメーター

名前方向
PcValuevoid*in
BaseOfImagevoid**out

戻り値の型: void*

各言語での呼び出し定義

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

void* RtlPcToFileHeader(
    void* PcValue,
    void** BaseOfImage
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern IntPtr RtlPcToFileHeader(
    IntPtr PcValue,   // void*
    IntPtr BaseOfImage   // void** out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function RtlPcToFileHeader(
    PcValue As IntPtr,   ' void*
    BaseOfImage As IntPtr   ' void** out
) As IntPtr
End Function
' PcValue : void*
' BaseOfImage : void** out
Declare PtrSafe Function RtlPcToFileHeader Lib "kernel32" ( _
    ByVal PcValue As LongPtr, _
    ByVal BaseOfImage As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlPcToFileHeader = ctypes.windll.kernel32.RtlPcToFileHeader
RtlPcToFileHeader.restype = ctypes.c_void_p
RtlPcToFileHeader.argtypes = [
    ctypes.POINTER(None),  # PcValue : void*
    ctypes.c_void_p,  # BaseOfImage : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
RtlPcToFileHeader = Fiddle::Function.new(
  lib['RtlPcToFileHeader'],
  [
    Fiddle::TYPE_VOIDP,  # PcValue : void*
    Fiddle::TYPE_VOIDP,  # BaseOfImage : void** out
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn RtlPcToFileHeader(
        PcValue: *mut (),  // void*
        BaseOfImage: *mut *mut ()  // void** out
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern IntPtr RtlPcToFileHeader(IntPtr PcValue, IntPtr BaseOfImage);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RtlPcToFileHeader' -Namespace Win32 -PassThru
# $api::RtlPcToFileHeader(PcValue, BaseOfImage)
#uselib "KERNEL32.dll"
#func global RtlPcToFileHeader "RtlPcToFileHeader" sptr, sptr
; RtlPcToFileHeader PcValue, BaseOfImage   ; 戻り値は stat
; PcValue : void* -> "sptr"
; BaseOfImage : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global RtlPcToFileHeader "RtlPcToFileHeader" sptr, sptr
; res = RtlPcToFileHeader(PcValue, BaseOfImage)
; PcValue : void* -> "sptr"
; BaseOfImage : void** out -> "sptr"
; void* RtlPcToFileHeader(void* PcValue, void** BaseOfImage)
#uselib "KERNEL32.dll"
#cfunc global RtlPcToFileHeader "RtlPcToFileHeader" intptr, intptr
; res = RtlPcToFileHeader(PcValue, BaseOfImage)
; PcValue : void* -> "intptr"
; BaseOfImage : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procRtlPcToFileHeader = kernel32.NewProc("RtlPcToFileHeader")
)

// PcValue (void*), BaseOfImage (void** out)
r1, _, err := procRtlPcToFileHeader.Call(
	uintptr(PcValue),
	uintptr(BaseOfImage),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function RtlPcToFileHeader(
  PcValue: Pointer;   // void*
  BaseOfImage: Pointer   // void** out
): Pointer; stdcall;
  external 'KERNEL32.dll' name 'RtlPcToFileHeader';
result := DllCall("KERNEL32\RtlPcToFileHeader"
    , "Ptr", PcValue   ; void*
    , "Ptr", BaseOfImage   ; void** out
    , "Ptr")   ; return: void*
●RtlPcToFileHeader(PcValue, BaseOfImage) = DLL("KERNEL32.dll", "void* RtlPcToFileHeader(void*, void*)")
# 呼び出し: RtlPcToFileHeader(PcValue, BaseOfImage)
# PcValue : void* -> "void*"
# BaseOfImage : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。