Kernel32VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) Method
Reserves, commits, or changes the state of a region of memory
within the virtual address space of a specified process.
The function initializes the memory it allocates to zero.
Namespace: DevCase.Win32.NativeMethodsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", ExactSpelling = true, SetLastError = true)]
public static IntPtr VirtualAllocEx(
IntPtr hProcess,
IntPtr address,
IntPtr size,
MemoryAllocationType allocationType,
MemoryProtectionOptions protection
)
<DllImportAttribute("Kernel32.dll", ExactSpelling := true, SetLastError := true>]
Public Shared Function VirtualAllocEx (
hProcess As IntPtr,
address As IntPtr,
size As IntPtr,
allocationType As MemoryAllocationType,
protection As MemoryProtectionOptions
) As IntPtr
Dim hProcess As IntPtr
Dim address As IntPtr
Dim size As IntPtr
Dim allocationType As MemoryAllocationType
Dim protection As MemoryProtectionOptions
Dim returnValue As IntPtr
returnValue = Kernel32.VirtualAllocEx(hProcess,
address, size, allocationType, protection)
public:
[DllImportAttribute(L"Kernel32.dll", ExactSpelling = true, SetLastError = true)]
static IntPtr VirtualAllocEx(
[InAttribute] IntPtr hProcess,
[InAttribute] IntPtr address,
IntPtr size,
MemoryAllocationType allocationType,
MemoryProtectionOptions protection
)
[<DllImportAttribute("Kernel32.dll", ExactSpelling = true, SetLastError = true)>]
static member VirtualAllocEx :
hProcess : IntPtr *
address : IntPtr *
size : IntPtr *
allocationType : MemoryAllocationType *
protection : MemoryProtectionOptions -> IntPtr
No code example is currently available or this language may not be supported.
- hProcess IntPtr
-
The handle to a process.
The function allocates memory within the virtual address space of this process.
The handle must have the VirtualMemoryOperation access right
- address IntPtr
-
The pointer that specifies a desired starting address for the region of pages that you want to allocate.
If you are reserving memory,
the function rounds this address down to the nearest multiple of the allocation granularity.
If you are committing memory that is already reserved,
the function rounds this address down to the nearest page boundary.
To determine the size of a page and the allocation granularity on the host computer,
use the GetSystemInfo function.
If address is Zero,
the function determines where to allocate the region.
If this address is within an enclave that you have not initialized by calling InitializeEnclave function,
VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) allocates a page of zeros for the enclave at that address.
The page must be previously uncommitted, and will not be measured with the EEXTEND instruction
of the Intel Software Guard Extensions programming model.
If the address in within an enclave that you initialized,
then the allocation operation fails with the ERROR_INVALID_ADDRESS error.
- size IntPtr
-
The size of the region of memory to allocate, in bytes.
If address is Zero,
the function rounds size up to the next page boundary.
If address is not Zero,
the function allocates all pages that contain one or more bytes in the range from
address to address+size.
This means, for example, that a 2-byte range that straddles a page boundary
causes the function to allocate both pages.
- allocationType MemoryAllocationType
-
The type of memory allocation.
- protection MemoryProtectionOptions
-
The memory protection for the region of pages to be allocated.
If address parameter specifies an address within an enclave,
protection cannot be any of the following values:
NoAccess,
Guard,
NoCache,
WriteCombine
IntPtr
If the function succeeds, the return value is the base address of the allocated region of pages.
If the function fails, the return value is
Zero.
To get extended error information, call
GetLastWin32Error.