K32QueryWorkingSetEx
関数シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL K32QueryWorkingSetEx(
HANDLE hProcess,
void* pv,
DWORD cb
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hProcess | HANDLE | in | プロセスのハンドルです。このハンドルには PROCESS_QUERY_INFORMATION アクセス権が必要です。詳細については、Process Security and Access Rights を参照してください。 |
| pv | void* | out | PSAPI_WORKING_SET_EX_INFORMATION 構造体の配列へのポインターです。入力時には、配列の各要素が対象となる仮想アドレスを指定します。出力時には、配列の各要素が対応する仮想ページに関する情報を受け取ります。 |
| cb | DWORD | in | pv バッファーのサイズ(バイト単位)です。 |
戻り値の型: BOOL
公式ドキュメント
指定したプロセスのアドレス空間内の特定の仮想アドレスにあるページについて、拡張情報を取得します。
戻り値
関数が成功した場合、戻り値は 0 以外の値になります。
関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出してください。
解説(Remarks)
対象プロセスのワーキングセットに限定される QueryWorkingSet 関数とは異なり、QueryWorkingSetEx 関数を使用すると、プロセスのワーキングセットには含まれないものの、AWE やラージページのようにプロセスの一部であるアドレスを照会できます。
Windows 7 および Windows Server 2008 R2 以降、Psapi.h は PSAPI 関数のバージョン番号を定めています。PSAPI のバージョン番号は、関数の呼び出しに使用する名前と、プログラムが読み込む必要のあるライブラリに影響します。
PSAPI_VERSION が 2 以上の場合、この関数は Psapi.h で K32QueryWorkingSetEx として定義され、Kernel32.lib および Kernel32.dll でエクスポートされます。PSAPI_VERSION が 1 の場合、この関数は Psapi.h で QueryWorkingSetEx として定義され、K32QueryWorkingSetEx を呼び出すラッパーとして Psapi.lib および Psapi.dll でエクスポートされます。
以前のバージョンの Windows と Windows 7 以降の両方で実行する必要があるプログラムは、常にこの関数を QueryWorkingSetEx として呼び出してください。シンボルを正しく解決するには、TARGETLIBS マクロに Psapi.lib を追加し、"–DPSAPI_VERSION=1" を指定してプログラムをコンパイルしてください。実行時の動的リンクを使用するには、Psapi.dll を読み込みます。
例
例については、Allocating Memory from a NUMA Node を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL K32QueryWorkingSetEx(
HANDLE hProcess,
void* pv,
DWORD cb
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool K32QueryWorkingSetEx(
IntPtr hProcess, // HANDLE
IntPtr pv, // void* out
uint cb // DWORD
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function K32QueryWorkingSetEx(
hProcess As IntPtr, ' HANDLE
pv As IntPtr, ' void* out
cb As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hProcess : HANDLE
' pv : void* out
' cb : DWORD
Declare PtrSafe Function K32QueryWorkingSetEx Lib "kernel32" ( _
ByVal hProcess As LongPtr, _
ByVal pv 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
K32QueryWorkingSetEx = ctypes.windll.kernel32.K32QueryWorkingSetEx
K32QueryWorkingSetEx.restype = wintypes.BOOL
K32QueryWorkingSetEx.argtypes = [
wintypes.HANDLE, # hProcess : HANDLE
ctypes.POINTER(None), # pv : void* out
wintypes.DWORD, # cb : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
K32QueryWorkingSetEx = Fiddle::Function.new(
lib['K32QueryWorkingSetEx'],
[
Fiddle::TYPE_VOIDP, # hProcess : HANDLE
Fiddle::TYPE_VOIDP, # pv : void* out
-Fiddle::TYPE_INT, # cb : DWORD
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn K32QueryWorkingSetEx(
hProcess: *mut core::ffi::c_void, // HANDLE
pv: *mut (), // void* out
cb: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool K32QueryWorkingSetEx(IntPtr hProcess, IntPtr pv, uint cb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_K32QueryWorkingSetEx' -Namespace Win32 -PassThru
# $api::K32QueryWorkingSetEx(hProcess, pv, cb)#uselib "KERNEL32.dll"
#func global K32QueryWorkingSetEx "K32QueryWorkingSetEx" sptr, sptr, sptr
; K32QueryWorkingSetEx hProcess, pv, cb ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; pv : void* out -> "sptr"
; cb : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global K32QueryWorkingSetEx "K32QueryWorkingSetEx" sptr, sptr, int
; res = K32QueryWorkingSetEx(hProcess, pv, cb)
; hProcess : HANDLE -> "sptr"
; pv : void* out -> "sptr"
; cb : DWORD -> "int"; BOOL K32QueryWorkingSetEx(HANDLE hProcess, void* pv, DWORD cb)
#uselib "KERNEL32.dll"
#cfunc global K32QueryWorkingSetEx "K32QueryWorkingSetEx" intptr, intptr, int
; res = K32QueryWorkingSetEx(hProcess, pv, cb)
; hProcess : HANDLE -> "intptr"
; pv : void* out -> "intptr"
; cb : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procK32QueryWorkingSetEx = kernel32.NewProc("K32QueryWorkingSetEx")
)
// hProcess (HANDLE), pv (void* out), cb (DWORD)
r1, _, err := procK32QueryWorkingSetEx.Call(
uintptr(hProcess),
uintptr(pv),
uintptr(cb),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction K32QueryWorkingSetEx(
hProcess: THandle; // HANDLE
pv: Pointer; // void* out
cb: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'K32QueryWorkingSetEx';result := DllCall("KERNEL32\K32QueryWorkingSetEx"
, "Ptr", hProcess ; HANDLE
, "Ptr", pv ; void* out
, "UInt", cb ; DWORD
, "Int") ; return: BOOL●K32QueryWorkingSetEx(hProcess, pv, cb) = DLL("KERNEL32.dll", "bool K32QueryWorkingSetEx(void*, void*, dword)")
# 呼び出し: K32QueryWorkingSetEx(hProcess, pv, cb)
# hProcess : HANDLE -> "void*"
# pv : void* out -> "void*"
# cb : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn K32QueryWorkingSetEx(
hProcess: ?*anyopaque, // HANDLE
pv: ?*anyopaque, // void* out
cb: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc K32QueryWorkingSetEx(
hProcess: pointer, # HANDLE
pv: pointer, # void* out
cb: uint32 # DWORD
): int32 {.importc: "K32QueryWorkingSetEx", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int K32QueryWorkingSetEx(
void* hProcess, // HANDLE
void* pv, // void* out
uint cb // DWORD
);ccall((:K32QueryWorkingSetEx, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt32),
hProcess, pv, cb)
# hProcess : HANDLE -> Ptr{Cvoid}
# pv : void* out -> Ptr{Cvoid}
# cb : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t K32QueryWorkingSetEx(
void* hProcess,
void* pv,
uint32_t cb);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.K32QueryWorkingSetEx(hProcess, pv, cb)
-- hProcess : HANDLE
-- pv : void* out
-- cb : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const K32QueryWorkingSetEx = lib.func('__stdcall', 'K32QueryWorkingSetEx', 'int32_t', ['void *', 'void *', 'uint32_t']);
// K32QueryWorkingSetEx(hProcess, pv, cb)
// hProcess : HANDLE -> 'void *'
// pv : void* out -> 'void *'
// cb : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
K32QueryWorkingSetEx: { parameters: ["pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.K32QueryWorkingSetEx(hProcess, pv, cb)
// hProcess : HANDLE -> "pointer"
// pv : void* out -> "pointer"
// cb : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t K32QueryWorkingSetEx(
void* hProcess,
void* pv,
uint32_t cb);
C, "KERNEL32.dll");
// $ffi->K32QueryWorkingSetEx(hProcess, pv, cb);
// hProcess : HANDLE
// pv : void* out
// cb : DWORD
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean K32QueryWorkingSetEx(
Pointer hProcess, // HANDLE
Pointer pv, // void* out
int cb // DWORD
);
}@[Link("kernel32")]
lib LibKERNEL32
fun K32QueryWorkingSetEx = K32QueryWorkingSetEx(
hProcess : Void*, # HANDLE
pv : Void*, # void* out
cb : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef K32QueryWorkingSetExNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef K32QueryWorkingSetExDart = int Function(Pointer<Void>, Pointer<Void>, int);
final K32QueryWorkingSetEx = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<K32QueryWorkingSetExNative, K32QueryWorkingSetExDart>('K32QueryWorkingSetEx');
// hProcess : HANDLE -> Pointer<Void>
// pv : void* out -> Pointer<Void>
// cb : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function K32QueryWorkingSetEx(
hProcess: THandle; // HANDLE
pv: Pointer; // void* out
cb: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'K32QueryWorkingSetEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "K32QueryWorkingSetEx"
c_K32QueryWorkingSetEx :: Ptr () -> Ptr () -> Word32 -> IO CInt
-- hProcess : HANDLE -> Ptr ()
-- pv : void* out -> Ptr ()
-- cb : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let k32queryworkingsetex =
foreign "K32QueryWorkingSetEx"
((ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hProcess : HANDLE -> (ptr void) *)
(* pv : void* out -> (ptr void) *)
(* cb : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("K32QueryWorkingSetEx" k32-query-working-set-ex :convention :stdcall) :int32
(h-process :pointer) ; HANDLE
(pv :pointer) ; void* out
(cb :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $K32QueryWorkingSetEx = Win32::API::More->new('KERNEL32',
'BOOL K32QueryWorkingSetEx(HANDLE hProcess, LPVOID pv, DWORD cb)');
# my $ret = $K32QueryWorkingSetEx->Call($hProcess, $pv, $cb);
# hProcess : HANDLE -> HANDLE
# pv : void* out -> LPVOID
# cb : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f K32QueryWorkingSet — 指定プロセスのワーキングセット情報を取得する。
- f EnumProcesses — 実行中の各プロセスの識別子を列挙して取得する。
- s PSAPI_WORKING_SET_EX_INFORMATION