Win32 API 日本語リファレンス
ホームSystem.ProcessStatus › K32GetModuleInformation

K32GetModuleInformation

関数
指定モジュールのベースアドレスやサイズ情報を取得する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

BOOL K32GetModuleInformation(
    HANDLE hProcess,
    HMODULE hModule,
    MODULEINFO* lpmodinfo,
    DWORD cb
);

パラメーター

名前方向
hProcessHANDLEin
hModuleHMODULEin
lpmodinfoMODULEINFO*out
cbDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL K32GetModuleInformation(
    HANDLE hProcess,
    HMODULE hModule,
    MODULEINFO* lpmodinfo,
    DWORD cb
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool K32GetModuleInformation(
    IntPtr hProcess,   // HANDLE
    IntPtr hModule,   // HMODULE
    IntPtr lpmodinfo,   // MODULEINFO* out
    uint cb   // DWORD
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function K32GetModuleInformation(
    hProcess As IntPtr,   ' HANDLE
    hModule As IntPtr,   ' HMODULE
    lpmodinfo As IntPtr,   ' MODULEINFO* out
    cb As UInteger   ' DWORD
) As Boolean
End Function
' hProcess : HANDLE
' hModule : HMODULE
' lpmodinfo : MODULEINFO* out
' cb : DWORD
Declare PtrSafe Function K32GetModuleInformation Lib "kernel32" ( _
    ByVal hProcess As LongPtr, _
    ByVal hModule As LongPtr, _
    ByVal lpmodinfo As LongPtr, _
    ByVal cb As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

K32GetModuleInformation = ctypes.windll.kernel32.K32GetModuleInformation
K32GetModuleInformation.restype = wintypes.BOOL
K32GetModuleInformation.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    wintypes.HANDLE,  # hModule : HMODULE
    ctypes.c_void_p,  # lpmodinfo : MODULEINFO* out
    wintypes.DWORD,  # cb : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
K32GetModuleInformation = Fiddle::Function.new(
  lib['K32GetModuleInformation'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    Fiddle::TYPE_VOIDP,  # hModule : HMODULE
    Fiddle::TYPE_VOIDP,  # lpmodinfo : MODULEINFO* out
    -Fiddle::TYPE_INT,  # cb : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn K32GetModuleInformation(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        hModule: *mut core::ffi::c_void,  // HMODULE
        lpmodinfo: *mut MODULEINFO,  // MODULEINFO* out
        cb: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool K32GetModuleInformation(IntPtr hProcess, IntPtr hModule, IntPtr lpmodinfo, uint cb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_K32GetModuleInformation' -Namespace Win32 -PassThru
# $api::K32GetModuleInformation(hProcess, hModule, lpmodinfo, cb)
#uselib "KERNEL32.dll"
#func global K32GetModuleInformation "K32GetModuleInformation" sptr, sptr, sptr, sptr
; K32GetModuleInformation hProcess, hModule, varptr(lpmodinfo), cb   ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; hModule : HMODULE -> "sptr"
; lpmodinfo : MODULEINFO* out -> "sptr"
; cb : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global K32GetModuleInformation "K32GetModuleInformation" sptr, sptr, var, int
; res = K32GetModuleInformation(hProcess, hModule, lpmodinfo, cb)
; hProcess : HANDLE -> "sptr"
; hModule : HMODULE -> "sptr"
; lpmodinfo : MODULEINFO* out -> "var"
; cb : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, MODULEINFO* lpmodinfo, DWORD cb)
#uselib "KERNEL32.dll"
#cfunc global K32GetModuleInformation "K32GetModuleInformation" intptr, intptr, var, int
; res = K32GetModuleInformation(hProcess, hModule, lpmodinfo, cb)
; hProcess : HANDLE -> "intptr"
; hModule : HMODULE -> "intptr"
; lpmodinfo : MODULEINFO* out -> "var"
; cb : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procK32GetModuleInformation = kernel32.NewProc("K32GetModuleInformation")
)

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