ホーム › System.Memory › VirtualAllocFromApp
VirtualAllocFromApp
関数UWPアプリ向けに仮想メモリを予約またはコミットする。
シグネチャ
// api-ms-win-core-memory-l1-1-3.dll
#include <windows.h>
void* VirtualAllocFromApp(
void* BaseAddress, // optional
UINT_PTR Size,
VIRTUAL_ALLOCATION_TYPE AllocationType,
DWORD Protection
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| BaseAddress | void* | inoptional |
| Size | UINT_PTR | in |
| AllocationType | VIRTUAL_ALLOCATION_TYPE | in |
| Protection | DWORD | in |
戻り値の型: void*
各言語での呼び出し定義
// api-ms-win-core-memory-l1-1-3.dll
#include <windows.h>
void* VirtualAllocFromApp(
void* BaseAddress, // optional
UINT_PTR Size,
VIRTUAL_ALLOCATION_TYPE AllocationType,
DWORD Protection
);[DllImport("api-ms-win-core-memory-l1-1-3.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocFromApp(
IntPtr BaseAddress, // void* optional
UIntPtr Size, // UINT_PTR
uint AllocationType, // VIRTUAL_ALLOCATION_TYPE
uint Protection // DWORD
);<DllImport("api-ms-win-core-memory-l1-1-3.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function VirtualAllocFromApp(
BaseAddress As IntPtr, ' void* optional
Size As UIntPtr, ' UINT_PTR
AllocationType As UInteger, ' VIRTUAL_ALLOCATION_TYPE
Protection As UInteger ' DWORD
) As IntPtr
End Function' BaseAddress : void* optional
' Size : UINT_PTR
' AllocationType : VIRTUAL_ALLOCATION_TYPE
' Protection : DWORD
Declare PtrSafe Function VirtualAllocFromApp Lib "api-ms-win-core-memory-l1-1-3" ( _
ByVal BaseAddress As LongPtr, _
ByVal Size As LongPtr, _
ByVal AllocationType As Long, _
ByVal Protection As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
VirtualAllocFromApp = ctypes.windll.LoadLibrary("api-ms-win-core-memory-l1-1-3.dll").VirtualAllocFromApp
VirtualAllocFromApp.restype = ctypes.c_void_p
VirtualAllocFromApp.argtypes = [
ctypes.POINTER(None), # BaseAddress : void* optional
ctypes.c_size_t, # Size : UINT_PTR
wintypes.DWORD, # AllocationType : VIRTUAL_ALLOCATION_TYPE
wintypes.DWORD, # Protection : 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-3.dll')
VirtualAllocFromApp = Fiddle::Function.new(
lib['VirtualAllocFromApp'],
[
Fiddle::TYPE_VOIDP, # BaseAddress : void* optional
Fiddle::TYPE_UINTPTR_T, # Size : UINT_PTR
-Fiddle::TYPE_INT, # AllocationType : VIRTUAL_ALLOCATION_TYPE
-Fiddle::TYPE_INT, # Protection : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "api-ms-win-core-memory-l1-1-3")]
extern "system" {
fn VirtualAllocFromApp(
BaseAddress: *mut (), // void* optional
Size: usize, // UINT_PTR
AllocationType: u32, // VIRTUAL_ALLOCATION_TYPE
Protection: u32 // DWORD
) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-core-memory-l1-1-3.dll", SetLastError = true)]
public static extern IntPtr VirtualAllocFromApp(IntPtr BaseAddress, UIntPtr Size, uint AllocationType, uint Protection);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-memory-l1-1-3_VirtualAllocFromApp' -Namespace Win32 -PassThru
# $api::VirtualAllocFromApp(BaseAddress, Size, AllocationType, Protection)#uselib "api-ms-win-core-memory-l1-1-3.dll"
#func global VirtualAllocFromApp "VirtualAllocFromApp" sptr, sptr, sptr, sptr
; VirtualAllocFromApp BaseAddress, Size, AllocationType, Protection ; 戻り値は stat
; BaseAddress : void* optional -> "sptr"
; Size : UINT_PTR -> "sptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "sptr"
; Protection : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-memory-l1-1-3.dll"
#cfunc global VirtualAllocFromApp "VirtualAllocFromApp" sptr, sptr, int, int
; res = VirtualAllocFromApp(BaseAddress, Size, AllocationType, Protection)
; BaseAddress : void* optional -> "sptr"
; Size : UINT_PTR -> "sptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int"
; Protection : DWORD -> "int"; void* VirtualAllocFromApp(void* BaseAddress, UINT_PTR Size, VIRTUAL_ALLOCATION_TYPE AllocationType, DWORD Protection)
#uselib "api-ms-win-core-memory-l1-1-3.dll"
#cfunc global VirtualAllocFromApp "VirtualAllocFromApp" intptr, intptr, int, int
; res = VirtualAllocFromApp(BaseAddress, Size, AllocationType, Protection)
; BaseAddress : void* optional -> "intptr"
; Size : UINT_PTR -> "intptr"
; AllocationType : VIRTUAL_ALLOCATION_TYPE -> "int"
; Protection : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_memory_l1_1_3 = windows.NewLazySystemDLL("api-ms-win-core-memory-l1-1-3.dll")
procVirtualAllocFromApp = api_ms_win_core_memory_l1_1_3.NewProc("VirtualAllocFromApp")
)
// BaseAddress (void* optional), Size (UINT_PTR), AllocationType (VIRTUAL_ALLOCATION_TYPE), Protection (DWORD)
r1, _, err := procVirtualAllocFromApp.Call(
uintptr(BaseAddress),
uintptr(Size),
uintptr(AllocationType),
uintptr(Protection),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function VirtualAllocFromApp(
BaseAddress: Pointer; // void* optional
Size: NativeUInt; // UINT_PTR
AllocationType: DWORD; // VIRTUAL_ALLOCATION_TYPE
Protection: DWORD // DWORD
): Pointer; stdcall;
external 'api-ms-win-core-memory-l1-1-3.dll' name 'VirtualAllocFromApp';result := DllCall("api-ms-win-core-memory-l1-1-3\VirtualAllocFromApp"
, "Ptr", BaseAddress ; void* optional
, "UPtr", Size ; UINT_PTR
, "UInt", AllocationType ; VIRTUAL_ALLOCATION_TYPE
, "UInt", Protection ; DWORD
, "Ptr") ; return: void*●VirtualAllocFromApp(BaseAddress, Size, AllocationType, Protection) = DLL("api-ms-win-core-memory-l1-1-3.dll", "void* VirtualAllocFromApp(void*, int, dword, dword)")
# 呼び出し: VirtualAllocFromApp(BaseAddress, Size, AllocationType, Protection)
# BaseAddress : void* optional -> "void*"
# Size : UINT_PTR -> "int"
# AllocationType : VIRTUAL_ALLOCATION_TYPE -> "dword"
# Protection : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。