Kernel32HeapAlloc Method

Allocates a block of memory from a heap. The allocated memory is not movable.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll")]
public static IntPtr HeapAlloc(
	IntPtr hHeap,
	HeapFlags flags,
	uint bytes
)

Parameters

hHeap  IntPtr
A handle to the heap from which the memory will be allocated.

This handle is returned by either the HeapCreate(HeapFlags, UInt32, UInt32) or GetProcessHeap function.

flags  HeapFlags
The heap allocation options.

Specifying any of the HeapFlags values will override the corresponding value specified when the heap was created with HeapCreate(HeapFlags, UInt32, UInt32).

bytes  UInt32
The number of bytes to be allocated.

If the heap specified by the hHeap parameter is a "non-growable" heap, bytes parameter must be less than 0x7FFF8.

You create a non-growable heap by calling the HeapCreate(HeapFlags, UInt32, UInt32) function passing a nonzero value to its maximumSize parameter.

Return Value

IntPtr
If the function succeeds, the return value is a pointer to the allocated memory block.

If the function fails and you have not specified GenerateExceptions, the return value is Zero.

If the function fails and you have specified GenerateExceptions, the function may generate an exception. The particular exception depends upon the nature of the heap corruption.

If the function fails, it does not call SetLastError(Win32ErrorCode). An application cannot call GetLastWin32Error for extended error information.

Remarks

See Also