ホーム › System.Memory › VirtualQueryEx
VirtualQueryEx
関数指定プロセス内の仮想アドレス領域に関する情報を取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
UINT_PTR VirtualQueryEx(
HANDLE hProcess,
const void* lpAddress, // optional
MEMORY_BASIC_INFORMATION* lpBuffer,
UINT_PTR dwLength
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hProcess | HANDLE | in |
| lpAddress | void* | inoptional |
| lpBuffer | MEMORY_BASIC_INFORMATION* | out |
| dwLength | UINT_PTR | in |
戻り値の型: UINT_PTR
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
UINT_PTR VirtualQueryEx(
HANDLE hProcess,
const void* lpAddress, // optional
MEMORY_BASIC_INFORMATION* lpBuffer,
UINT_PTR dwLength
);[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern UIntPtr VirtualQueryEx(
IntPtr hProcess, // HANDLE
IntPtr lpAddress, // void* optional
IntPtr lpBuffer, // MEMORY_BASIC_INFORMATION* out
UIntPtr dwLength // UINT_PTR
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function VirtualQueryEx(
hProcess As IntPtr, ' HANDLE
lpAddress As IntPtr, ' void* optional
lpBuffer As IntPtr, ' MEMORY_BASIC_INFORMATION* out
dwLength As UIntPtr ' UINT_PTR
) As UIntPtr
End Function' hProcess : HANDLE
' lpAddress : void* optional
' lpBuffer : MEMORY_BASIC_INFORMATION* out
' dwLength : UINT_PTR
Declare PtrSafe Function VirtualQueryEx Lib "kernel32" ( _
ByVal hProcess As LongPtr, _
ByVal lpAddress As LongPtr, _
ByVal lpBuffer As LongPtr, _
ByVal dwLength As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VirtualQueryEx = ctypes.windll.kernel32.VirtualQueryEx
VirtualQueryEx.restype = ctypes.c_size_t
VirtualQueryEx.argtypes = [
wintypes.HANDLE, # hProcess : HANDLE
ctypes.POINTER(None), # lpAddress : void* optional
ctypes.c_void_p, # lpBuffer : MEMORY_BASIC_INFORMATION* out
ctypes.c_size_t, # dwLength : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
VirtualQueryEx = Fiddle::Function.new(
lib['VirtualQueryEx'],
[
Fiddle::TYPE_VOIDP, # hProcess : HANDLE
Fiddle::TYPE_VOIDP, # lpAddress : void* optional
Fiddle::TYPE_VOIDP, # lpBuffer : MEMORY_BASIC_INFORMATION* out
Fiddle::TYPE_UINTPTR_T, # dwLength : UINT_PTR
],
Fiddle::TYPE_UINTPTR_T)#[link(name = "kernel32")]
extern "system" {
fn VirtualQueryEx(
hProcess: *mut core::ffi::c_void, // HANDLE
lpAddress: *const (), // void* optional
lpBuffer: *mut MEMORY_BASIC_INFORMATION, // MEMORY_BASIC_INFORMATION* out
dwLength: usize // UINT_PTR
) -> usize;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern UIntPtr VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, IntPtr lpBuffer, UIntPtr dwLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_VirtualQueryEx' -Namespace Win32 -PassThru
# $api::VirtualQueryEx(hProcess, lpAddress, lpBuffer, dwLength)#uselib "KERNEL32.dll"
#func global VirtualQueryEx "VirtualQueryEx" sptr, sptr, sptr, sptr
; VirtualQueryEx hProcess, lpAddress, varptr(lpBuffer), dwLength ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; lpAddress : void* optional -> "sptr"
; lpBuffer : MEMORY_BASIC_INFORMATION* out -> "sptr"
; dwLength : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global VirtualQueryEx "VirtualQueryEx" sptr, sptr, var, sptr ; res = VirtualQueryEx(hProcess, lpAddress, lpBuffer, dwLength) ; hProcess : HANDLE -> "sptr" ; lpAddress : void* optional -> "sptr" ; lpBuffer : MEMORY_BASIC_INFORMATION* out -> "var" ; dwLength : UINT_PTR -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global VirtualQueryEx "VirtualQueryEx" sptr, sptr, sptr, sptr ; res = VirtualQueryEx(hProcess, lpAddress, varptr(lpBuffer), dwLength) ; hProcess : HANDLE -> "sptr" ; lpAddress : void* optional -> "sptr" ; lpBuffer : MEMORY_BASIC_INFORMATION* out -> "sptr" ; dwLength : UINT_PTR -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; UINT_PTR VirtualQueryEx(HANDLE hProcess, void* lpAddress, MEMORY_BASIC_INFORMATION* lpBuffer, UINT_PTR dwLength) #uselib "KERNEL32.dll" #cfunc global VirtualQueryEx "VirtualQueryEx" intptr, intptr, var, intptr ; res = VirtualQueryEx(hProcess, lpAddress, lpBuffer, dwLength) ; hProcess : HANDLE -> "intptr" ; lpAddress : void* optional -> "intptr" ; lpBuffer : MEMORY_BASIC_INFORMATION* out -> "var" ; dwLength : UINT_PTR -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; UINT_PTR VirtualQueryEx(HANDLE hProcess, void* lpAddress, MEMORY_BASIC_INFORMATION* lpBuffer, UINT_PTR dwLength) #uselib "KERNEL32.dll" #cfunc global VirtualQueryEx "VirtualQueryEx" intptr, intptr, intptr, intptr ; res = VirtualQueryEx(hProcess, lpAddress, varptr(lpBuffer), dwLength) ; hProcess : HANDLE -> "intptr" ; lpAddress : void* optional -> "intptr" ; lpBuffer : MEMORY_BASIC_INFORMATION* out -> "intptr" ; dwLength : UINT_PTR -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procVirtualQueryEx = kernel32.NewProc("VirtualQueryEx")
)
// hProcess (HANDLE), lpAddress (void* optional), lpBuffer (MEMORY_BASIC_INFORMATION* out), dwLength (UINT_PTR)
r1, _, err := procVirtualQueryEx.Call(
uintptr(hProcess),
uintptr(lpAddress),
uintptr(lpBuffer),
uintptr(dwLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // UINT_PTRfunction VirtualQueryEx(
hProcess: THandle; // HANDLE
lpAddress: Pointer; // void* optional
lpBuffer: Pointer; // MEMORY_BASIC_INFORMATION* out
dwLength: NativeUInt // UINT_PTR
): NativeUInt; stdcall;
external 'KERNEL32.dll' name 'VirtualQueryEx';result := DllCall("KERNEL32\VirtualQueryEx"
, "Ptr", hProcess ; HANDLE
, "Ptr", lpAddress ; void* optional
, "Ptr", lpBuffer ; MEMORY_BASIC_INFORMATION* out
, "UPtr", dwLength ; UINT_PTR
, "UPtr") ; return: UINT_PTR●VirtualQueryEx(hProcess, lpAddress, lpBuffer, dwLength) = DLL("KERNEL32.dll", "int VirtualQueryEx(void*, void*, void*, int)")
# 呼び出し: VirtualQueryEx(hProcess, lpAddress, lpBuffer, dwLength)
# hProcess : HANDLE -> "void*"
# lpAddress : void* optional -> "void*"
# lpBuffer : MEMORY_BASIC_INFORMATION* out -> "void*"
# dwLength : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。