Platform SDK: Memory |
The GetProcessHeap function obtains a handle to the heap of the calling process. This handle can then be used in subsequent calls to the HeapAlloc, HeapReAlloc, HeapFree, and HeapSize functions.
HANDLE GetProcessHeap(VOID);
This function has no parameters.
If the function succeeds, the return value is a handle to the calling process's heap.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
The GetProcessHeap function allows you to allocate memory from the process heap without having to first create a heap with the HeapCreate function, as shown in this example:
HeapAlloc(GetProcessHeap(), 0, dwBytes);
Note The handle obtained by calling this function should not be used in calls to the HeapDestroy function.
To guard against an access violation, use structured exception handling to protect any code that writes to or reads from a heap. For more information on structured exception handling with memory accesses, see Reading and Writing and Structured Exception Handling.
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Memory Management Overview, Memory Management Functions, HeapAlloc, HeapCreate, HeapDestroy, HeapFree, HeapReAlloc, HeapSize