> For the complete documentation index, see [llms.txt](https://www.pinvoke.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pinvoke.dev/kernel32/virtualallocex.md).

# VirtualAllocEx

```csharp
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern unsafe void* VirtualAllocEx(
    HANDLE hProcess,
    [Optional] void* lpAddress,
    nuint dwSize,
    VIRTUAL_ALLOCATION_TYPE flAllocationType,
    PAGE_PROTECTION_FLAGS flProtect);
```

[VIRTUAL\_ALLOCATION\_TYPE](/memory/virtual_allocation_type.md)

[PAGE\_PROTECTION\_FLAGS](/memory/page_protection_flags.md)
