Heap32First function (tlhelp32.h)

Retrieves information about the first block of a heap that has been allocated by a process.


BOOL Heap32First(
  [in, out] LPHEAPENTRY32 lphe,
  [in]      DWORD         th32ProcessID,
  [in]      ULONG_PTR     th32HeapID


[in, out] lphe

A pointer to a HEAPENTRY32 structure.

[in] th32ProcessID

The identifier of the process context that owns the heap.

[in] th32HeapID

The identifier of the heap to be enumerated.

Return value

Returns TRUE if information for the first heap block has been copied to the buffer or FALSE otherwise. The ERROR_NO_MORE_FILES error value is returned by the GetLastError function if the heap is invalid or empty.


The calling application must set the dwSize member of HEAPENTRY32 to the size, in bytes, of the structure. Heap32First changes dwSize to the number of bytes written to the structure. This will never be greater than the initial value of dwSize, but it may be smaller. If the value is smaller, do not rely on the values of any members whose offsets are greater than this value.

To access subsequent blocks of the same heap, use the Heap32Next function.

Walking the heap with Heap32First and Heap32Next is inefficient, particularly for large heaps. Use HeapWalk instead.


For an example, see Traversing the Heap List.


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header tlhelp32.h
Library Kernel32.lib
DLL Kernel32.dll

See also


Heap Lists and Heap Walking


Tool Help Functions