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

HeapQueryInformation

関数
ヒープの動作に関する情報を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL HeapQueryInformation(
    HANDLE HeapHandle,   // optional
    HEAP_INFORMATION_CLASS HeapInformationClass,
    void* HeapInformation,   // optional
    UINT_PTR HeapInformationLength,
    UINT_PTR* ReturnLength   // optional
);

パラメーター

名前方向
HeapHandleHANDLEinoptional
HeapInformationClassHEAP_INFORMATION_CLASSin
HeapInformationvoid*outoptional
HeapInformationLengthUINT_PTRin
ReturnLengthUINT_PTR*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL HeapQueryInformation(
    HANDLE HeapHandle,   // optional
    HEAP_INFORMATION_CLASS HeapInformationClass,
    void* HeapInformation,   // optional
    UINT_PTR HeapInformationLength,
    UINT_PTR* ReturnLength   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool HeapQueryInformation(
    IntPtr HeapHandle,   // HANDLE optional
    int HeapInformationClass,   // HEAP_INFORMATION_CLASS
    IntPtr HeapInformation,   // void* optional, out
    UIntPtr HeapInformationLength,   // UINT_PTR
    IntPtr ReturnLength   // UINT_PTR* optional, out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HeapQueryInformation(
    HeapHandle As IntPtr,   ' HANDLE optional
    HeapInformationClass As Integer,   ' HEAP_INFORMATION_CLASS
    HeapInformation As IntPtr,   ' void* optional, out
    HeapInformationLength As UIntPtr,   ' UINT_PTR
    ReturnLength As IntPtr   ' UINT_PTR* optional, out
) As Boolean
End Function
' HeapHandle : HANDLE optional
' HeapInformationClass : HEAP_INFORMATION_CLASS
' HeapInformation : void* optional, out
' HeapInformationLength : UINT_PTR
' ReturnLength : UINT_PTR* optional, out
Declare PtrSafe Function HeapQueryInformation Lib "kernel32" ( _
    ByVal HeapHandle As LongPtr, _
    ByVal HeapInformationClass As Long, _
    ByVal HeapInformation As LongPtr, _
    ByVal HeapInformationLength As LongPtr, _
    ByVal ReturnLength As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HeapQueryInformation = ctypes.windll.kernel32.HeapQueryInformation
HeapQueryInformation.restype = wintypes.BOOL
HeapQueryInformation.argtypes = [
    wintypes.HANDLE,  # HeapHandle : HANDLE optional
    ctypes.c_int,  # HeapInformationClass : HEAP_INFORMATION_CLASS
    ctypes.POINTER(None),  # HeapInformation : void* optional, out
    ctypes.c_size_t,  # HeapInformationLength : UINT_PTR
    ctypes.POINTER(ctypes.c_size_t),  # ReturnLength : UINT_PTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procHeapQueryInformation = kernel32.NewProc("HeapQueryInformation")
)

// HeapHandle (HANDLE optional), HeapInformationClass (HEAP_INFORMATION_CLASS), HeapInformation (void* optional, out), HeapInformationLength (UINT_PTR), ReturnLength (UINT_PTR* optional, out)
r1, _, err := procHeapQueryInformation.Call(
	uintptr(HeapHandle),
	uintptr(HeapInformationClass),
	uintptr(HeapInformation),
	uintptr(HeapInformationLength),
	uintptr(ReturnLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function HeapQueryInformation(
  HeapHandle: THandle;   // HANDLE optional
  HeapInformationClass: Integer;   // HEAP_INFORMATION_CLASS
  HeapInformation: Pointer;   // void* optional, out
  HeapInformationLength: NativeUInt;   // UINT_PTR
  ReturnLength: Pointer   // UINT_PTR* optional, out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'HeapQueryInformation';
result := DllCall("KERNEL32\HeapQueryInformation"
    , "Ptr", HeapHandle   ; HANDLE optional
    , "Int", HeapInformationClass   ; HEAP_INFORMATION_CLASS
    , "Ptr", HeapInformation   ; void* optional, out
    , "UPtr", HeapInformationLength   ; UINT_PTR
    , "Ptr", ReturnLength   ; UINT_PTR* optional, out
    , "Int")   ; return: BOOL
●HeapQueryInformation(HeapHandle, HeapInformationClass, HeapInformation, HeapInformationLength, ReturnLength) = DLL("KERNEL32.dll", "bool HeapQueryInformation(void*, int, void*, int, void*)")
# 呼び出し: HeapQueryInformation(HeapHandle, HeapInformationClass, HeapInformation, HeapInformationLength, ReturnLength)
# HeapHandle : HANDLE optional -> "void*"
# HeapInformationClass : HEAP_INFORMATION_CLASS -> "int"
# HeapInformation : void* optional, out -> "void*"
# HeapInformationLength : UINT_PTR -> "int"
# ReturnLength : UINT_PTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。