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

K32EnumPageFilesW

関数
システムのページファイル情報をUnicodeで列挙する。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL K32EnumPageFilesW(
    PENUM_PAGE_FILE_CALLBACKW pCallBackRoutine,
    void* pContext
);

パラメーター

名前方向説明
pCallBackRoutinePENUM_PAGE_FILE_CALLBACKWin各ページファイルに対して呼び出されるルーチンへのポインターです。詳細については、 EnumPageFilesProc を参照してください。
pContextvoid*inoutコールバックルーチンに渡されるユーザー定義のデータです。

戻り値の型: BOOL

公式ドキュメント

システムにインストールされている各ページファイルに対してコールバックルーチンを呼び出します。(ANSI)

戻り値

関数が成功した場合、戻り値は TRUE です。関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出してください。

解説(Remarks)

Windows 7 および Windows Server 2008 R2 以降、Psapi.h は PSAPI 関数のバージョン番号を定義します。PSAPI のバージョン番号は、関数の呼び出しに使用される名前と、プログラムがロードする必要があるライブラリに影響します。

PSAPI_VERSION が 2 以上の場合、この関数は Psapi.h で K32EnumPageFiles として定義され、Kernel32.lib および Kernel32.dll でエクスポートされます。PSAPI_VERSION が 1 の場合、この関数は Psapi.h で EnumPageFiles として定義され、K32EnumPageFiles を呼び出すラッパーとして Psapi.lib および Psapi.dll でエクスポートされます。

以前のバージョンの Windows と Windows 7 以降のバージョンの両方で実行する必要があるプログラムは、常にこの関数を EnumPageFiles として呼び出してください。シンボルが正しく解決されるようにするには、TARGETLIBS マクロに Psapi.lib を追加し、–DPSAPI_VERSION=1 を指定してプログラムをコンパイルします。実行時の動的リンクを使用するには、Psapi.dll をロードします。

メモ

psapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして EnumPageFiles を定義します。エンコーディングに依存しないエイリアスの使用を、エンコーディングに依存しないわけではないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL K32EnumPageFilesW(
    PENUM_PAGE_FILE_CALLBACKW pCallBackRoutine,
    void* pContext
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool K32EnumPageFilesW(
    IntPtr pCallBackRoutine,   // PENUM_PAGE_FILE_CALLBACKW
    IntPtr pContext   // void* in/out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function K32EnumPageFilesW(
    pCallBackRoutine As IntPtr,   ' PENUM_PAGE_FILE_CALLBACKW
    pContext As IntPtr   ' void* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW
' pContext : void* in/out
Declare PtrSafe Function K32EnumPageFilesW Lib "kernel32" ( _
    ByVal pCallBackRoutine As LongPtr, _
    ByVal pContext As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

K32EnumPageFilesW = ctypes.windll.kernel32.K32EnumPageFilesW
K32EnumPageFilesW.restype = wintypes.BOOL
K32EnumPageFilesW.argtypes = [
    ctypes.c_void_p,  # pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW
    ctypes.POINTER(None),  # pContext : void* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
K32EnumPageFilesW = Fiddle::Function.new(
  lib['K32EnumPageFilesW'],
  [
    Fiddle::TYPE_VOIDP,  # pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW
    Fiddle::TYPE_VOIDP,  # pContext : void* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn K32EnumPageFilesW(
        pCallBackRoutine: *const core::ffi::c_void,  // PENUM_PAGE_FILE_CALLBACKW
        pContext: *mut ()  // void* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern bool K32EnumPageFilesW(IntPtr pCallBackRoutine, IntPtr pContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_K32EnumPageFilesW' -Namespace Win32 -PassThru
# $api::K32EnumPageFilesW(pCallBackRoutine, pContext)
#uselib "KERNEL32.dll"
#func global K32EnumPageFilesW "K32EnumPageFilesW" wptr, wptr
; K32EnumPageFilesW pCallBackRoutine, pContext   ; 戻り値は stat
; pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> "wptr"
; pContext : void* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global K32EnumPageFilesW "K32EnumPageFilesW" sptr, sptr
; res = K32EnumPageFilesW(pCallBackRoutine, pContext)
; pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> "sptr"
; pContext : void* in/out -> "sptr"
; BOOL K32EnumPageFilesW(PENUM_PAGE_FILE_CALLBACKW pCallBackRoutine, void* pContext)
#uselib "KERNEL32.dll"
#cfunc global K32EnumPageFilesW "K32EnumPageFilesW" intptr, intptr
; res = K32EnumPageFilesW(pCallBackRoutine, pContext)
; pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> "intptr"
; pContext : void* in/out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procK32EnumPageFilesW = kernel32.NewProc("K32EnumPageFilesW")
)

// pCallBackRoutine (PENUM_PAGE_FILE_CALLBACKW), pContext (void* in/out)
r1, _, err := procK32EnumPageFilesW.Call(
	uintptr(pCallBackRoutine),
	uintptr(pContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function K32EnumPageFilesW(
  pCallBackRoutine: Pointer;   // PENUM_PAGE_FILE_CALLBACKW
  pContext: Pointer   // void* in/out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'K32EnumPageFilesW';
result := DllCall("KERNEL32\K32EnumPageFilesW"
    , "Ptr", pCallBackRoutine   ; PENUM_PAGE_FILE_CALLBACKW
    , "Ptr", pContext   ; void* in/out
    , "Int")   ; return: BOOL
●K32EnumPageFilesW(pCallBackRoutine, pContext) = DLL("KERNEL32.dll", "bool K32EnumPageFilesW(void*, void*)")
# 呼び出し: K32EnumPageFilesW(pCallBackRoutine, pContext)
# pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> "void*"
# pContext : void* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "kernel32" fn K32EnumPageFilesW(
    pCallBackRoutine: ?*anyopaque, // PENUM_PAGE_FILE_CALLBACKW
    pContext: ?*anyopaque // void* in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc K32EnumPageFilesW(
    pCallBackRoutine: pointer,  # PENUM_PAGE_FILE_CALLBACKW
    pContext: pointer  # void* in/out
): int32 {.importc: "K32EnumPageFilesW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
int K32EnumPageFilesW(
    void* pCallBackRoutine,   // PENUM_PAGE_FILE_CALLBACKW
    void* pContext   // void* in/out
);
ccall((:K32EnumPageFilesW, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}),
      pCallBackRoutine, pContext)
# pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> Ptr{Cvoid}
# pContext : void* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t K32EnumPageFilesW(
    void* pCallBackRoutine,
    void* pContext);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.K32EnumPageFilesW(pCallBackRoutine, pContext)
-- pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW
-- pContext : void* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const K32EnumPageFilesW = lib.func('__stdcall', 'K32EnumPageFilesW', 'int32_t', ['void *', 'void *']);
// K32EnumPageFilesW(pCallBackRoutine, pContext)
// pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> 'void *'
// pContext : void* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("KERNEL32.dll", {
  K32EnumPageFilesW: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.K32EnumPageFilesW(pCallBackRoutine, pContext)
// pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> "pointer"
// pContext : void* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t K32EnumPageFilesW(
    void* pCallBackRoutine,
    void* pContext);
C, "KERNEL32.dll");
// $ffi->K32EnumPageFilesW(pCallBackRoutine, pContext);
// pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW
// pContext : void* in/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    boolean K32EnumPageFilesW(
        Callback pCallBackRoutine,   // PENUM_PAGE_FILE_CALLBACKW
        Pointer pContext   // void* in/out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun K32EnumPageFilesW = K32EnumPageFilesW(
    pCallBackRoutine : Void*,   # PENUM_PAGE_FILE_CALLBACKW
    pContext : Void*   # void* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef K32EnumPageFilesWNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef K32EnumPageFilesWDart = int Function(Pointer<Void>, Pointer<Void>);
final K32EnumPageFilesW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<K32EnumPageFilesWNative, K32EnumPageFilesWDart>('K32EnumPageFilesW');
// pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> Pointer<Void>
// pContext : void* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function K32EnumPageFilesW(
  pCallBackRoutine: Pointer;   // PENUM_PAGE_FILE_CALLBACKW
  pContext: Pointer   // void* in/out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'K32EnumPageFilesW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "K32EnumPageFilesW"
  c_K32EnumPageFilesW :: Ptr () -> Ptr () -> IO CInt
-- pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> Ptr ()
-- pContext : void* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let k32enumpagefilesw =
  foreign "K32EnumPageFilesW"
    ((ptr void) @-> (ptr void) @-> returning int32_t)
(* pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> (ptr void) *)
(* pContext : void* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("K32EnumPageFilesW" k32-enum-page-files-w :convention :stdcall) :int32
  (p-call-back-routine :pointer)   ; PENUM_PAGE_FILE_CALLBACKW
  (p-context :pointer))   ; void* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $K32EnumPageFilesW = Win32::API::More->new('KERNEL32',
    'BOOL K32EnumPageFilesW(LPVOID pCallBackRoutine, LPVOID pContext)');
# my $ret = $K32EnumPageFilesW->Call($pCallBackRoutine, $pContext);
# pCallBackRoutine : PENUM_PAGE_FILE_CALLBACKW -> LPVOID
# pContext : void* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型