ホーム › System.ProcessStatus › GetModuleInformation
GetModuleInformation
関数指定モジュールのベースアドレスやサイズ情報を取得する。
シグネチャ
// PSAPI.dll
#include <windows.h>
BOOL GetModuleInformation(
HANDLE hProcess,
HMODULE hModule,
MODULEINFO* lpmodinfo,
DWORD cb
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hProcess | HANDLE | in |
| hModule | HMODULE | in |
| lpmodinfo | MODULEINFO* | out |
| cb | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// PSAPI.dll
#include <windows.h>
BOOL GetModuleInformation(
HANDLE hProcess,
HMODULE hModule,
MODULEINFO* lpmodinfo,
DWORD cb
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("PSAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetModuleInformation(
IntPtr hProcess, // HANDLE
IntPtr hModule, // HMODULE
IntPtr lpmodinfo, // MODULEINFO* out
uint cb // DWORD
);<DllImport("PSAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetModuleInformation(
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 GetModuleInformation Lib "psapi" ( _
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
GetModuleInformation = ctypes.windll.psapi.GetModuleInformation
GetModuleInformation.restype = wintypes.BOOL
GetModuleInformation.argtypes = [
wintypes.HANDLE, # hProcess : HANDLE
wintypes.HANDLE, # hModule : HMODULE
ctypes.c_void_p, # lpmodinfo : MODULEINFO* out
wintypes.DWORD, # cb : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('PSAPI.dll')
GetModuleInformation = Fiddle::Function.new(
lib['GetModuleInformation'],
[
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 = "psapi")]
extern "system" {
fn GetModuleInformation(
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("PSAPI.dll", SetLastError = true)]
public static extern bool GetModuleInformation(IntPtr hProcess, IntPtr hModule, IntPtr lpmodinfo, uint cb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'PSAPI_GetModuleInformation' -Namespace Win32 -PassThru
# $api::GetModuleInformation(hProcess, hModule, lpmodinfo, cb)#uselib "PSAPI.dll"
#func global GetModuleInformation "GetModuleInformation" sptr, sptr, sptr, sptr
; GetModuleInformation hProcess, hModule, varptr(lpmodinfo), cb ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; hModule : HMODULE -> "sptr"
; lpmodinfo : MODULEINFO* out -> "sptr"
; cb : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "PSAPI.dll" #cfunc global GetModuleInformation "GetModuleInformation" sptr, sptr, var, int ; res = GetModuleInformation(hProcess, hModule, lpmodinfo, cb) ; hProcess : HANDLE -> "sptr" ; hModule : HMODULE -> "sptr" ; lpmodinfo : MODULEINFO* out -> "var" ; cb : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "PSAPI.dll" #cfunc global GetModuleInformation "GetModuleInformation" sptr, sptr, sptr, int ; res = GetModuleInformation(hProcess, hModule, varptr(lpmodinfo), cb) ; hProcess : HANDLE -> "sptr" ; hModule : HMODULE -> "sptr" ; lpmodinfo : MODULEINFO* out -> "sptr" ; cb : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetModuleInformation(HANDLE hProcess, HMODULE hModule, MODULEINFO* lpmodinfo, DWORD cb) #uselib "PSAPI.dll" #cfunc global GetModuleInformation "GetModuleInformation" intptr, intptr, var, int ; res = GetModuleInformation(hProcess, hModule, lpmodinfo, cb) ; hProcess : HANDLE -> "intptr" ; hModule : HMODULE -> "intptr" ; lpmodinfo : MODULEINFO* out -> "var" ; cb : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetModuleInformation(HANDLE hProcess, HMODULE hModule, MODULEINFO* lpmodinfo, DWORD cb) #uselib "PSAPI.dll" #cfunc global GetModuleInformation "GetModuleInformation" intptr, intptr, intptr, int ; res = GetModuleInformation(hProcess, hModule, varptr(lpmodinfo), cb) ; hProcess : HANDLE -> "intptr" ; hModule : HMODULE -> "intptr" ; lpmodinfo : MODULEINFO* out -> "intptr" ; cb : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
psapi = windows.NewLazySystemDLL("PSAPI.dll")
procGetModuleInformation = psapi.NewProc("GetModuleInformation")
)
// hProcess (HANDLE), hModule (HMODULE), lpmodinfo (MODULEINFO* out), cb (DWORD)
r1, _, err := procGetModuleInformation.Call(
uintptr(hProcess),
uintptr(hModule),
uintptr(lpmodinfo),
uintptr(cb),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetModuleInformation(
hProcess: THandle; // HANDLE
hModule: THandle; // HMODULE
lpmodinfo: Pointer; // MODULEINFO* out
cb: DWORD // DWORD
): BOOL; stdcall;
external 'PSAPI.dll' name 'GetModuleInformation';result := DllCall("PSAPI\GetModuleInformation"
, "Ptr", hProcess ; HANDLE
, "Ptr", hModule ; HMODULE
, "Ptr", lpmodinfo ; MODULEINFO* out
, "UInt", cb ; DWORD
, "Int") ; return: BOOL●GetModuleInformation(hProcess, hModule, lpmodinfo, cb) = DLL("PSAPI.dll", "bool GetModuleInformation(void*, void*, void*, dword)")
# 呼び出し: GetModuleInformation(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)。