ホーム › System.Memory › QueryVirtualMemoryInformation
QueryVirtualMemoryInformation
関数指定仮想アドレスのメモリ情報をクラス別に問い合わせる。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Process | HANDLE | in | クエリ対象のページが存在するコンテキストを持つプロセスのハンドルです。 |
| VirtualAddress | void* | in | クエリ対象となるページ領域のアドレスです。この値は、次のホストページアドレス境界へ切り下げられます。 |
| MemoryInformationClass | WIN32_MEMORY_INFORMATION_CLASS | in | 取得するメモリ情報のクラスです。サポートされている値は MemoryRegionInfo のみです。 |
| MemoryInformation | void* | out | 指定した情報を受け取るバッファーへのポインターです。 MemoryInformationClass パラメーターの値が MemoryRegionInfo の場合、このパラメーターは WIN32_MEMORY_REGION_INFORMATION 構造体を指している必要があります。 |
| MemoryInformationSize | UINT_PTR | in | メモリ情報バッファーの長さをバイト単位で指定します。 |
| ReturnSize | UINT_PTR* | outoptional | 省略可能なポインターです。指定した場合、メモリ情報バッファーに格納されたバイト数を受け取ります。 |
戻り値の型: BOOL
公式ドキュメント
QueryVirtualMemoryInformation 関数は、指定したプロセスの仮想アドレス空間内にあるページまたはページの集合に関する情報を返します。
戻り値
成功した場合は TRUE を返します。失敗した場合は FALSE を返します。拡張エラー情報を取得するには、GetLastError を呼び出してください。
解説(Remarks)
MemoryInformationClass パラメーターの値が MemoryRegionInfo の場合、MemoryInformation パラメーターは WIN32_MEMORY_REGION_INFORMATION 構造体を指している必要があります。VirtualAddress パラメーターは、有効なメモリ割り当て内のアドレスを指している必要があります。VirtualAddress パラメーターが未割り当てのメモリ領域を指している場合、この関数は失敗します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "api-ms-win-core-memory-l1-1-4.dll" #cfunc global QueryVirtualMemoryInformation "QueryVirtualMemoryInformation" sptr, sptr, int, sptr, sptr, sptr ; res = QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, varptr(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 -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr ; res = QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, varptr(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 -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "api-ms-win-core-memory-l1-1-4" fn QueryVirtualMemoryInformation(
Process: ?*anyopaque, // HANDLE
VirtualAddress: ?*anyopaque, // void*
MemoryInformationClass: i32, // WIN32_MEMORY_INFORMATION_CLASS
MemoryInformation: ?*anyopaque, // void* out
MemoryInformationSize: usize, // UINT_PTR
ReturnSize: [*c]usize // UINT_PTR* optional, out
) callconv(std.os.windows.WINAPI) i32;proc QueryVirtualMemoryInformation(
Process: pointer, # HANDLE
VirtualAddress: pointer, # void*
MemoryInformationClass: int32, # WIN32_MEMORY_INFORMATION_CLASS
MemoryInformation: pointer, # void* out
MemoryInformationSize: uint, # UINT_PTR
ReturnSize: ptr uint # UINT_PTR* optional, out
): int32 {.importc: "QueryVirtualMemoryInformation", stdcall, dynlib: "api-ms-win-core-memory-l1-1-4.dll".}pragma(lib, "api-ms-win-core-memory-l1-1-4");
extern(Windows)
int QueryVirtualMemoryInformation(
void* Process, // HANDLE
void* VirtualAddress, // void*
int MemoryInformationClass, // WIN32_MEMORY_INFORMATION_CLASS
void* MemoryInformation, // void* out
size_t MemoryInformationSize, // UINT_PTR
size_t* ReturnSize // UINT_PTR* optional, out
);ccall((:QueryVirtualMemoryInformation, "api-ms-win-core-memory-l1-1-4.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Int32, Ptr{Cvoid}, Csize_t, Ptr{Csize_t}),
Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
# Process : HANDLE -> Ptr{Cvoid}
# VirtualAddress : void* -> Ptr{Cvoid}
# MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> Int32
# MemoryInformation : void* out -> Ptr{Cvoid}
# MemoryInformationSize : UINT_PTR -> Csize_t
# ReturnSize : UINT_PTR* optional, out -> Ptr{Csize_t}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t QueryVirtualMemoryInformation(
void* Process,
void* VirtualAddress,
int32_t MemoryInformationClass,
void* MemoryInformation,
uintptr_t MemoryInformationSize,
uintptr_t* ReturnSize);
]]
local api-ms-win-core-memory-l1-1-4 = ffi.load("api-ms-win-core-memory-l1-1-4")
-- api-ms-win-core-memory-l1-1-4.QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
-- Process : HANDLE
-- VirtualAddress : void*
-- MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS
-- MemoryInformation : void* out
-- MemoryInformationSize : UINT_PTR
-- ReturnSize : UINT_PTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-memory-l1-1-4.dll');
const QueryVirtualMemoryInformation = lib.func('__stdcall', 'QueryVirtualMemoryInformation', 'int32_t', ['void *', 'void *', 'int32_t', 'void *', 'uintptr_t', 'uintptr_t *']);
// QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
// Process : HANDLE -> 'void *'
// VirtualAddress : void* -> 'void *'
// MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> 'int32_t'
// MemoryInformation : void* out -> 'void *'
// MemoryInformationSize : UINT_PTR -> 'uintptr_t'
// ReturnSize : UINT_PTR* optional, out -> 'uintptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-memory-l1-1-4.dll", {
QueryVirtualMemoryInformation: { parameters: ["pointer", "pointer", "i32", "pointer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize)
// Process : HANDLE -> "pointer"
// VirtualAddress : void* -> "pointer"
// MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> "i32"
// MemoryInformation : void* out -> "pointer"
// MemoryInformationSize : UINT_PTR -> "usize"
// ReturnSize : UINT_PTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t QueryVirtualMemoryInformation(
void* Process,
void* VirtualAddress,
int32_t MemoryInformationClass,
void* MemoryInformation,
size_t MemoryInformationSize,
size_t* ReturnSize);
C, "api-ms-win-core-memory-l1-1-4.dll");
// $ffi->QueryVirtualMemoryInformation(Process, VirtualAddress, MemoryInformationClass, MemoryInformation, MemoryInformationSize, ReturnSize);
// Process : HANDLE
// VirtualAddress : void*
// MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS
// MemoryInformation : void* out
// MemoryInformationSize : UINT_PTR
// ReturnSize : UINT_PTR* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Api-ms-win-core-memory-l1-1-4 extends StdCallLibrary {
Api-ms-win-core-memory-l1-1-4 INSTANCE = Native.load("api-ms-win-core-memory-l1-1-4", Api-ms-win-core-memory-l1-1-4.class);
boolean QueryVirtualMemoryInformation(
Pointer Process, // HANDLE
Pointer VirtualAddress, // void*
int MemoryInformationClass, // WIN32_MEMORY_INFORMATION_CLASS
Pointer MemoryInformation, // void* out
long MemoryInformationSize, // UINT_PTR
LongByReference ReturnSize // UINT_PTR* optional, out
);
}@[Link("api-ms-win-core-memory-l1-1-4")]
lib Libapi-ms-win-core-memory-l1-1-4
fun QueryVirtualMemoryInformation = QueryVirtualMemoryInformation(
Process : Void*, # HANDLE
VirtualAddress : Void*, # void*
MemoryInformationClass : Int32, # WIN32_MEMORY_INFORMATION_CLASS
MemoryInformation : Void*, # void* out
MemoryInformationSize : LibC::SizeT, # UINT_PTR
ReturnSize : LibC::SizeT* # UINT_PTR* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef QueryVirtualMemoryInformationNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32, Pointer<Void>, UintPtr, Pointer<UintPtr>);
typedef QueryVirtualMemoryInformationDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, int, Pointer<UintPtr>);
final QueryVirtualMemoryInformation = DynamicLibrary.open('api-ms-win-core-memory-l1-1-4.dll')
.lookupFunction<QueryVirtualMemoryInformationNative, QueryVirtualMemoryInformationDart>('QueryVirtualMemoryInformation');
// Process : HANDLE -> Pointer<Void>
// VirtualAddress : void* -> Pointer<Void>
// MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> Int32
// MemoryInformation : void* out -> Pointer<Void>
// MemoryInformationSize : UINT_PTR -> UintPtr
// ReturnSize : UINT_PTR* optional, out -> Pointer<UintPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "QueryVirtualMemoryInformation"
c_QueryVirtualMemoryInformation :: Ptr () -> Ptr () -> Int32 -> Ptr () -> CUIntPtr -> Ptr CUIntPtr -> IO CInt
-- Process : HANDLE -> Ptr ()
-- VirtualAddress : void* -> Ptr ()
-- MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> Int32
-- MemoryInformation : void* out -> Ptr ()
-- MemoryInformationSize : UINT_PTR -> CUIntPtr
-- ReturnSize : UINT_PTR* optional, out -> Ptr CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let queryvirtualmemoryinformation =
foreign "QueryVirtualMemoryInformation"
((ptr void) @-> (ptr void) @-> int32_t @-> (ptr void) @-> size_t @-> (ptr size_t) @-> returning int32_t)
(* Process : HANDLE -> (ptr void) *)
(* VirtualAddress : void* -> (ptr void) *)
(* MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> int32_t *)
(* MemoryInformation : void* out -> (ptr void) *)
(* MemoryInformationSize : UINT_PTR -> size_t *)
(* ReturnSize : UINT_PTR* optional, out -> (ptr size_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-memory-l1-1-4 (t "api-ms-win-core-memory-l1-1-4.dll"))
(cffi:use-foreign-library api-ms-win-core-memory-l1-1-4)
(cffi:defcfun ("QueryVirtualMemoryInformation" query-virtual-memory-information :convention :stdcall) :int32
(process :pointer) ; HANDLE
(virtual-address :pointer) ; void*
(memory-information-class :int32) ; WIN32_MEMORY_INFORMATION_CLASS
(memory-information :pointer) ; void* out
(memory-information-size :uint64) ; UINT_PTR
(return-size :pointer)) ; UINT_PTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $QueryVirtualMemoryInformation = Win32::API::More->new('api-ms-win-core-memory-l1-1-4',
'BOOL QueryVirtualMemoryInformation(HANDLE Process, LPVOID VirtualAddress, int MemoryInformationClass, LPVOID MemoryInformation, WPARAM MemoryInformationSize, LPVOID ReturnSize)');
# my $ret = $QueryVirtualMemoryInformation->Call($Process, $VirtualAddress, $MemoryInformationClass, $MemoryInformation, $MemoryInformationSize, $ReturnSize);
# Process : HANDLE -> HANDLE
# VirtualAddress : void* -> LPVOID
# MemoryInformationClass : WIN32_MEMORY_INFORMATION_CLASS -> int
# MemoryInformation : void* out -> LPVOID
# MemoryInformationSize : UINT_PTR -> WPARAM
# ReturnSize : UINT_PTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetLastError — 呼び出しスレッドの最終エラーコードを取得する。
- s MEMORY_BASIC_INFORMATION
- s WIN32_MEMORY_REGION_INFORMATION