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

VirtualAlloc2FromApp

関数
UWPアプリ向けに拡張パラメータ付きで仮想メモリを割り当てる。
DLLapi-ms-win-core-memory-l1-1-6.dll呼出規約winapiSetLastErrorあり対応OSWindows 10 以降

シグネチャ

// api-ms-win-core-memory-l1-1-6.dll
#include <windows.h>

void* VirtualAlloc2FromApp(
    HANDLE Process,   // optional
    void* BaseAddress,   // optional
    UINT_PTR Size,
    VIRTUAL_ALLOCATION_TYPE AllocationType,
    DWORD PageProtection,
    MEM_EXTENDED_PARAMETER* ExtendedParameters,   // optional
    DWORD ParameterCount
);

パラメーター

名前方向
ProcessHANDLEinoptional
BaseAddressvoid*inoptional
SizeUINT_PTRin
AllocationTypeVIRTUAL_ALLOCATION_TYPEin
PageProtectionDWORDin
ExtendedParametersMEM_EXTENDED_PARAMETER*inoutoptional
ParameterCountDWORDin

戻り値の型: void*

各言語での呼び出し定義

// api-ms-win-core-memory-l1-1-6.dll
#include <windows.h>

void* VirtualAlloc2FromApp(
    HANDLE Process,   // optional
    void* BaseAddress,   // optional
    UINT_PTR Size,
    VIRTUAL_ALLOCATION_TYPE AllocationType,
    DWORD PageProtection,
    MEM_EXTENDED_PARAMETER* ExtendedParameters,   // optional
    DWORD ParameterCount
);
[DllImport("api-ms-win-core-memory-l1-1-6.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAlloc2FromApp(
    IntPtr Process,   // HANDLE optional
    IntPtr BaseAddress,   // void* optional
    UIntPtr Size,   // UINT_PTR
    uint AllocationType,   // VIRTUAL_ALLOCATION_TYPE
    uint PageProtection,   // DWORD
    IntPtr ExtendedParameters,   // MEM_EXTENDED_PARAMETER* optional, in/out
    uint ParameterCount   // DWORD
);
<DllImport("api-ms-win-core-memory-l1-1-6.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function VirtualAlloc2FromApp(
    Process As IntPtr,   ' HANDLE optional
    BaseAddress As IntPtr,   ' void* optional
    Size As UIntPtr,   ' UINT_PTR
    AllocationType As UInteger,   ' VIRTUAL_ALLOCATION_TYPE
    PageProtection As UInteger,   ' DWORD
    ExtendedParameters As IntPtr,   ' MEM_EXTENDED_PARAMETER* optional, in/out
    ParameterCount As UInteger   ' DWORD
) As IntPtr
End Function
' Process : HANDLE optional
' BaseAddress : void* optional
' Size : UINT_PTR
' AllocationType : VIRTUAL_ALLOCATION_TYPE
' PageProtection : DWORD
' ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
' ParameterCount : DWORD
Declare PtrSafe Function VirtualAlloc2FromApp Lib "api-ms-win-core-memory-l1-1-6" ( _
    ByVal Process As LongPtr, _
    ByVal BaseAddress As LongPtr, _
    ByVal Size As LongPtr, _
    ByVal AllocationType As Long, _
    ByVal PageProtection As Long, _
    ByVal ExtendedParameters As LongPtr, _
    ByVal ParameterCount As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

VirtualAlloc2FromApp = ctypes.windll.LoadLibrary("api-ms-win-core-memory-l1-1-6.dll").VirtualAlloc2FromApp
VirtualAlloc2FromApp.restype = ctypes.c_void_p
VirtualAlloc2FromApp.argtypes = [
    wintypes.HANDLE,  # Process : HANDLE optional
    ctypes.POINTER(None),  # BaseAddress : void* optional
    ctypes.c_size_t,  # Size : UINT_PTR
    wintypes.DWORD,  # AllocationType : VIRTUAL_ALLOCATION_TYPE
    wintypes.DWORD,  # PageProtection : DWORD
    ctypes.c_void_p,  # ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
    wintypes.DWORD,  # ParameterCount : DWORD
]
# 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-6.dll')
VirtualAlloc2FromApp = Fiddle::Function.new(
  lib['VirtualAlloc2FromApp'],
  [
    Fiddle::TYPE_VOIDP,  # Process : HANDLE optional
    Fiddle::TYPE_VOIDP,  # BaseAddress : void* optional
    Fiddle::TYPE_UINTPTR_T,  # Size : UINT_PTR
    -Fiddle::TYPE_INT,  # AllocationType : VIRTUAL_ALLOCATION_TYPE
    -Fiddle::TYPE_INT,  # PageProtection : DWORD
    Fiddle::TYPE_VOIDP,  # ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
    -Fiddle::TYPE_INT,  # ParameterCount : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "api-ms-win-core-memory-l1-1-6")]
extern "system" {
    fn VirtualAlloc2FromApp(
        Process: *mut core::ffi::c_void,  // HANDLE optional
        BaseAddress: *mut (),  // void* optional
        Size: usize,  // UINT_PTR
        AllocationType: u32,  // VIRTUAL_ALLOCATION_TYPE
        PageProtection: u32,  // DWORD
        ExtendedParameters: *mut MEM_EXTENDED_PARAMETER,  // MEM_EXTENDED_PARAMETER* optional, in/out
        ParameterCount: u32  // DWORD
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-core-memory-l1-1-6.dll", SetLastError = true)]
public static extern IntPtr VirtualAlloc2FromApp(IntPtr Process, IntPtr BaseAddress, UIntPtr Size, uint AllocationType, uint PageProtection, IntPtr ExtendedParameters, uint ParameterCount);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-memory-l1-1-6_VirtualAlloc2FromApp' -Namespace Win32 -PassThru
# $api::VirtualAlloc2FromApp(Process, BaseAddress, Size, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
#uselib "api-ms-win-core-memory-l1-1-6.dll"
#func global VirtualAlloc2FromApp "VirtualAlloc2FromApp" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; VirtualAlloc2FromApp Process, BaseAddress, Size, AllocationType, PageProtection, varptr(ExtendedParameters), ParameterCount   ; 戻り値は stat
; Process : HANDLE optional -> "sptr"
; BaseAddress : void* optional -> "sptr"
; Size : UINT_PTR -> "sptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "sptr"
; PageProtection : DWORD -> "sptr"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "sptr"
; ParameterCount : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-memory-l1-1-6.dll"
#cfunc global VirtualAlloc2FromApp "VirtualAlloc2FromApp" sptr, sptr, sptr, int, int, var, int
; res = VirtualAlloc2FromApp(Process, BaseAddress, Size, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
; Process : HANDLE optional -> "sptr"
; BaseAddress : void* optional -> "sptr"
; Size : UINT_PTR -> "sptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int"
; PageProtection : DWORD -> "int"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "var"
; ParameterCount : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* VirtualAlloc2FromApp(HANDLE Process, void* BaseAddress, UINT_PTR Size, VIRTUAL_ALLOCATION_TYPE AllocationType, DWORD PageProtection, MEM_EXTENDED_PARAMETER* ExtendedParameters, DWORD ParameterCount)
#uselib "api-ms-win-core-memory-l1-1-6.dll"
#cfunc global VirtualAlloc2FromApp "VirtualAlloc2FromApp" intptr, intptr, intptr, int, int, var, int
; res = VirtualAlloc2FromApp(Process, BaseAddress, Size, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
; Process : HANDLE optional -> "intptr"
; BaseAddress : void* optional -> "intptr"
; Size : UINT_PTR -> "intptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int"
; PageProtection : DWORD -> "int"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "var"
; ParameterCount : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_memory_l1_1_6 = windows.NewLazySystemDLL("api-ms-win-core-memory-l1-1-6.dll")
	procVirtualAlloc2FromApp = api_ms_win_core_memory_l1_1_6.NewProc("VirtualAlloc2FromApp")
)

// Process (HANDLE optional), BaseAddress (void* optional), Size (UINT_PTR), AllocationType (VIRTUAL_ALLOCATION_TYPE), PageProtection (DWORD), ExtendedParameters (MEM_EXTENDED_PARAMETER* optional, in/out), ParameterCount (DWORD)
r1, _, err := procVirtualAlloc2FromApp.Call(
	uintptr(Process),
	uintptr(BaseAddress),
	uintptr(Size),
	uintptr(AllocationType),
	uintptr(PageProtection),
	uintptr(ExtendedParameters),
	uintptr(ParameterCount),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function VirtualAlloc2FromApp(
  Process: THandle;   // HANDLE optional
  BaseAddress: Pointer;   // void* optional
  Size: NativeUInt;   // UINT_PTR
  AllocationType: DWORD;   // VIRTUAL_ALLOCATION_TYPE
  PageProtection: DWORD;   // DWORD
  ExtendedParameters: Pointer;   // MEM_EXTENDED_PARAMETER* optional, in/out
  ParameterCount: DWORD   // DWORD
): Pointer; stdcall;
  external 'api-ms-win-core-memory-l1-1-6.dll' name 'VirtualAlloc2FromApp';
result := DllCall("api-ms-win-core-memory-l1-1-6\VirtualAlloc2FromApp"
    , "Ptr", Process   ; HANDLE optional
    , "Ptr", BaseAddress   ; void* optional
    , "UPtr", Size   ; UINT_PTR
    , "UInt", AllocationType   ; VIRTUAL_ALLOCATION_TYPE
    , "UInt", PageProtection   ; DWORD
    , "Ptr", ExtendedParameters   ; MEM_EXTENDED_PARAMETER* optional, in/out
    , "UInt", ParameterCount   ; DWORD
    , "Ptr")   ; return: void*
●VirtualAlloc2FromApp(Process, BaseAddress, Size, AllocationType, PageProtection, ExtendedParameters, ParameterCount) = DLL("api-ms-win-core-memory-l1-1-6.dll", "void* VirtualAlloc2FromApp(void*, void*, int, dword, dword, void*, dword)")
# 呼び出し: VirtualAlloc2FromApp(Process, BaseAddress, Size, AllocationType, PageProtection, ExtendedParameters, ParameterCount)
# Process : HANDLE optional -> "void*"
# BaseAddress : void* optional -> "void*"
# Size : UINT_PTR -> "int"
# AllocationType : VIRTUAL_ALLOCATION_TYPE -> "dword"
# PageProtection : DWORD -> "dword"
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "void*"
# ParameterCount : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。