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

MapUserPhysicalPages

関数
AWE物理ページを仮想アドレス領域にマップする。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL MapUserPhysicalPages(
    void* VirtualAddress,
    UINT_PTR NumberOfPages,
    UINT_PTR* PageArray   // optional
);

パラメーター

名前方向
VirtualAddressvoid*in
NumberOfPagesUINT_PTRin
PageArrayUINT_PTR*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

MapUserPhysicalPages = ctypes.windll.kernel32.MapUserPhysicalPages
MapUserPhysicalPages.restype = wintypes.BOOL
MapUserPhysicalPages.argtypes = [
    ctypes.POINTER(None),  # VirtualAddress : void*
    ctypes.c_size_t,  # NumberOfPages : UINT_PTR
    ctypes.POINTER(ctypes.c_size_t),  # PageArray : UINT_PTR* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
MapUserPhysicalPages = Fiddle::Function.new(
  lib['MapUserPhysicalPages'],
  [
    Fiddle::TYPE_VOIDP,  # VirtualAddress : void*
    Fiddle::TYPE_UINTPTR_T,  # NumberOfPages : UINT_PTR
    Fiddle::TYPE_VOIDP,  # PageArray : UINT_PTR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn MapUserPhysicalPages(
        VirtualAddress: *mut (),  // void*
        NumberOfPages: usize,  // UINT_PTR
        PageArray: *mut usize  // UINT_PTR* optional
    ) -> 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 MapUserPhysicalPages(IntPtr VirtualAddress, UIntPtr NumberOfPages, IntPtr PageArray);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_MapUserPhysicalPages' -Namespace Win32 -PassThru
# $api::MapUserPhysicalPages(VirtualAddress, NumberOfPages, PageArray)
#uselib "KERNEL32.dll"
#func global MapUserPhysicalPages "MapUserPhysicalPages" sptr, sptr, sptr
; MapUserPhysicalPages VirtualAddress, NumberOfPages, varptr(PageArray)   ; 戻り値は stat
; VirtualAddress : void* -> "sptr"
; NumberOfPages : UINT_PTR -> "sptr"
; PageArray : UINT_PTR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global MapUserPhysicalPages "MapUserPhysicalPages" sptr, sptr, var
; res = MapUserPhysicalPages(VirtualAddress, NumberOfPages, PageArray)
; VirtualAddress : void* -> "sptr"
; NumberOfPages : UINT_PTR -> "sptr"
; PageArray : UINT_PTR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL MapUserPhysicalPages(void* VirtualAddress, UINT_PTR NumberOfPages, UINT_PTR* PageArray)
#uselib "KERNEL32.dll"
#cfunc global MapUserPhysicalPages "MapUserPhysicalPages" intptr, intptr, var
; res = MapUserPhysicalPages(VirtualAddress, NumberOfPages, PageArray)
; VirtualAddress : void* -> "intptr"
; NumberOfPages : UINT_PTR -> "intptr"
; PageArray : UINT_PTR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procMapUserPhysicalPages = kernel32.NewProc("MapUserPhysicalPages")
)

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