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

SymGetModuleBase

関数
指定アドレスを含むモジュールのベースアドレスを取得する。
DLLdbghelp.dll呼出規約winapiSetLastErrorあり

シグネチャ

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

DWORD SymGetModuleBase(
    HANDLE hProcess,
    DWORD dwAddr
);

パラメーター

名前方向
hProcessHANDLEin
dwAddrDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD SymGetModuleBase(
    HANDLE hProcess,
    DWORD dwAddr
);
[DllImport("dbghelp.dll", SetLastError = true, ExactSpelling = true)]
static extern uint SymGetModuleBase(
    IntPtr hProcess,   // HANDLE
    uint dwAddr   // DWORD
);
<DllImport("dbghelp.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SymGetModuleBase(
    hProcess As IntPtr,   ' HANDLE
    dwAddr As UInteger   ' DWORD
) As UInteger
End Function
' hProcess : HANDLE
' dwAddr : DWORD
Declare PtrSafe Function SymGetModuleBase Lib "dbghelp" ( _
    ByVal hProcess As LongPtr, _
    ByVal dwAddr As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SymGetModuleBase = ctypes.windll.dbghelp.SymGetModuleBase
SymGetModuleBase.restype = wintypes.DWORD
SymGetModuleBase.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    wintypes.DWORD,  # dwAddr : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dbghelp.dll')
SymGetModuleBase = Fiddle::Function.new(
  lib['SymGetModuleBase'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    -Fiddle::TYPE_INT,  # dwAddr : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dbghelp")]
extern "system" {
    fn SymGetModuleBase(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        dwAddr: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("dbghelp.dll", SetLastError = true)]
public static extern uint SymGetModuleBase(IntPtr hProcess, uint dwAddr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dbghelp_SymGetModuleBase' -Namespace Win32 -PassThru
# $api::SymGetModuleBase(hProcess, dwAddr)
#uselib "dbghelp.dll"
#func global SymGetModuleBase "SymGetModuleBase" sptr, sptr
; SymGetModuleBase hProcess, dwAddr   ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; dwAddr : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "dbghelp.dll"
#cfunc global SymGetModuleBase "SymGetModuleBase" sptr, int
; res = SymGetModuleBase(hProcess, dwAddr)
; hProcess : HANDLE -> "sptr"
; dwAddr : DWORD -> "int"
; DWORD SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
#uselib "dbghelp.dll"
#cfunc global SymGetModuleBase "SymGetModuleBase" intptr, int
; res = SymGetModuleBase(hProcess, dwAddr)
; hProcess : HANDLE -> "intptr"
; dwAddr : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dbghelp = windows.NewLazySystemDLL("dbghelp.dll")
	procSymGetModuleBase = dbghelp.NewProc("SymGetModuleBase")
)

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