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

QueryVirtualMemoryInformation

関数
指定仮想アドレスのメモリ情報をクラス別に問い合わせる。
DLLapi-ms-win-core-memory-l1-1-4.dll呼出規約winapiSetLastErrorあり対応OSWindows 10 以降

シグネチャ

// api-ms-win-core-memory-l1-1-4.dll
#include <windows.h>

BOOL QueryVirtualMemoryInformation(
    HANDLE Process,
    const void* VirtualAddress,
    WIN32_MEMORY_INFORMATION_CLASS MemoryInformationClass,
    void* MemoryInformation,
    UINT_PTR MemoryInformationSize,
    UINT_PTR* ReturnSize   // optional
);

パラメーター

名前方向
ProcessHANDLEin
VirtualAddressvoid*in
MemoryInformationClassWIN32_MEMORY_INFORMATION_CLASSin
MemoryInformationvoid*out
MemoryInformationSizeUINT_PTRin
ReturnSizeUINT_PTR*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

// api-ms-win-core-memory-l1-1-4.dll
#include <windows.h>

BOOL QueryVirtualMemoryInformation(
    HANDLE Process,
    const void* VirtualAddress,
    WIN32_MEMORY_INFORMATION_CLASS MemoryInformationClass,
    void* MemoryInformation,
    UINT_PTR MemoryInformationSize,
    UINT_PTR* ReturnSize   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-memory-l1-1-4.dll", SetLastError = true, ExactSpelling = true)]
static extern bool QueryVirtualMemoryInformation(
    IntPtr Process,   // HANDLE
    IntPtr VirtualAddress,   // void*
    int MemoryInformationClass,   // WIN32_MEMORY_INFORMATION_CLASS
    IntPtr MemoryInformation,   // void* out
    UIntPtr MemoryInformationSize,   // UINT_PTR
    IntPtr ReturnSize   // UINT_PTR* optional, out
);
<DllImport("api-ms-win-core-memory-l1-1-4.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function QueryVirtualMemoryInformation(
    Process As IntPtr,   ' HANDLE
    VirtualAddress As IntPtr,   ' void*
    MemoryInformationClass As Integer,   ' WIN32_MEMORY_INFORMATION_CLASS
    MemoryInformation As IntPtr,   ' void* out
    MemoryInformationSize As UIntPtr,   ' UINT_PTR
    ReturnSize As IntPtr   ' UINT_PTR* optional, out
) As Boolean
End Function
' Process : HANDLE
' VirtualAddress : void*
' MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS
' MemoryInformation : void* out
' MemoryInformationSize : UINT_PTR
' ReturnSize : UINT_PTR* optional, out
Declare PtrSafe Function QueryVirtualMemoryInformation Lib "api-ms-win-core-memory-l1-1-4" ( _
    ByVal Process As LongPtr, _
    ByVal VirtualAddress As LongPtr, _
    ByVal MemoryInformationClass As Long, _
    ByVal MemoryInformation As LongPtr, _
    ByVal MemoryInformationSize As LongPtr, _
    ByVal ReturnSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

QueryVirtualMemoryInformation = ctypes.windll.LoadLibrary("api-ms-win-core-memory-l1-1-4.dll").QueryVirtualMemoryInformation
QueryVirtualMemoryInformation.restype = wintypes.BOOL
QueryVirtualMemoryInformation.argtypes = [
    wintypes.HANDLE,  # Process : HANDLE
    ctypes.POINTER(None),  # VirtualAddress : void*
    ctypes.c_int,  # MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS
    ctypes.POINTER(None),  # MemoryInformation : void* out
    ctypes.c_size_t,  # MemoryInformationSize : UINT_PTR
    ctypes.POINTER(ctypes.c_size_t),  # ReturnSize : UINT_PTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-memory-l1-1-4.dll')
QueryVirtualMemoryInformation = Fiddle::Function.new(
  lib['QueryVirtualMemoryInformation'],
  [
    Fiddle::TYPE_VOIDP,  # Process : HANDLE
    Fiddle::TYPE_VOIDP,  # VirtualAddress : void*
    Fiddle::TYPE_INT,  # MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS
    Fiddle::TYPE_VOIDP,  # MemoryInformation : void* out
    Fiddle::TYPE_UINTPTR_T,  # MemoryInformationSize : UINT_PTR
    Fiddle::TYPE_VOIDP,  # ReturnSize : UINT_PTR* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-memory-l1-1-4")]
extern "system" {
    fn QueryVirtualMemoryInformation(
        Process: *mut core::ffi::c_void,  // HANDLE
        VirtualAddress: *const (),  // void*
        MemoryInformationClass: i32,  // WIN32_MEMORY_INFORMATION_CLASS
        MemoryInformation: *mut (),  // void* out
        MemoryInformationSize: usize,  // UINT_PTR
        ReturnSize: *mut usize  // UINT_PTR* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-memory-l1-1-4.dll", SetLastError = true)]
public static extern bool QueryVirtualMemoryInformation(IntPtr Process, IntPtr VirtualAddress, int MemoryInformationClass, IntPtr MemoryInformation, UIntPtr MemoryInformationSize, IntPtr ReturnSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-memory-l1-1-4_QueryVirtualMemoryInformation' -Namespace Win32 -PassThru
# $api::QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
#uselib "api-ms-win-core-memory-l1-1-4.dll"
#func global QueryVirtualMemoryInformation "QueryVirtualMemoryInformation" sptr, sptr, sptr, sptr, sptr, sptr
; QueryVirtualMemoryInformation Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, varptr(ReturnSize)   ; 戻り値は stat
; Process : HANDLE -> "sptr"
; VirtualAddress : void* -> "sptr"
; MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> "sptr"
; MemoryInformation : void* out -> "sptr"
; MemoryInformationSize : UINT_PTR -> "sptr"
; ReturnSize : UINT_PTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-memory-l1-1-4.dll"
#cfunc global QueryVirtualMemoryInformation "QueryVirtualMemoryInformation" sptr, sptr, int, sptr, sptr, var
; res = QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
; Process : HANDLE -> "sptr"
; VirtualAddress : void* -> "sptr"
; MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> "int"
; MemoryInformation : void* out -> "sptr"
; MemoryInformationSize : UINT_PTR -> "sptr"
; ReturnSize : UINT_PTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL QueryVirtualMemoryInformation(HANDLE Process, void* VirtualAddress, WIN32_MEMORY_INFORMATION_CLASS MemoryInformationClass, void* MemoryInformation, UINT_PTR MemoryInformationSize, UINT_PTR* ReturnSize)
#uselib "api-ms-win-core-memory-l1-1-4.dll"
#cfunc global QueryVirtualMemoryInformation "QueryVirtualMemoryInformation" intptr, intptr, int, intptr, intptr, var
; res = QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
; Process : HANDLE -> "intptr"
; VirtualAddress : void* -> "intptr"
; MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> "int"
; MemoryInformation : void* out -> "intptr"
; MemoryInformationSize : UINT_PTR -> "intptr"
; ReturnSize : UINT_PTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_memory_l1_1_4 = windows.NewLazySystemDLL("api-ms-win-core-memory-l1-1-4.dll")
	procQueryVirtualMemoryInformation = api_ms_win_core_memory_l1_1_4.NewProc("QueryVirtualMemoryInformation")
)

// Process (HANDLE), VirtualAddress (void*), MemoryInformationClass (WIN32_MEMORY_INFORMATION_CLASS), MemoryInformation (void* out), MemoryInformationSize (UINT_PTR), ReturnSize (UINT_PTR* optional, out)
r1, _, err := procQueryVirtualMemoryInformation.Call(
	uintptr(Process),
	uintptr(VirtualAddress),
	uintptr(MemoryInformationClass),
	uintptr(MemoryInformation),
	uintptr(MemoryInformationSize),
	uintptr(ReturnSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function QueryVirtualMemoryInformation(
  Process: THandle;   // HANDLE
  VirtualAddress: Pointer;   // void*
  MemoryInformationClass: Integer;   // WIN32_MEMORY_INFORMATION_CLASS
  MemoryInformation: Pointer;   // void* out
  MemoryInformationSize: NativeUInt;   // UINT_PTR
  ReturnSize: Pointer   // UINT_PTR* optional, out
): BOOL; stdcall;
  external 'api-ms-win-core-memory-l1-1-4.dll' name 'QueryVirtualMemoryInformation';
result := DllCall("api-ms-win-core-memory-l1-1-4\QueryVirtualMemoryInformation"
    , "Ptr", Process   ; HANDLE
    , "Ptr", VirtualAddress   ; void*
    , "Int", MemoryInformationClass   ; WIN32_MEMORY_INFORMATION_CLASS
    , "Ptr", MemoryInformation   ; void* out
    , "UPtr", MemoryInformationSize   ; UINT_PTR
    , "Ptr", ReturnSize   ; UINT_PTR* optional, out
    , "Int")   ; return: BOOL
●QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize) = DLL("api-ms-win-core-memory-l1-1-4.dll", "bool QueryVirtualMemoryInformation(void*, void*, int, void*, int, void*)")
# 呼び出し: QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
# Process : HANDLE -> "void*"
# VirtualAddress : void* -> "void*"
# MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> "int"
# MemoryInformation : void* out -> "void*"
# MemoryInformationSize : UINT_PTR -> "int"
# ReturnSize : UINT_PTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。