Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Heap32ListFirst (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool Heap32ListFirst(IntPtr hSnapshot, ref HEAPLIST32 lphl);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

        uint process_id = 1234;

        IntPtr heaplist_h = CreateToolhelp32Snapshot( (uint)ToolHelp.SnapshotFlags.HeapList,
            (uint) process_id);

        if (heaplist_h == ToolHelp.INVALID_HANDLE_VALUE)
        {
        int err = Marshal.GetLastWin32Error();

        textBox1.AppendText("Cant create shapshot. Err: " + err.ToString("X") + "\n");
        if (err == ToolHelp.ERROR_ACCESS_DENIED) // win32-64 or something like that
            wr("  Access denied\n");
        return;
        }

        HEAPLIST32 hlist = new ToolHelp.HEAPLIST32();
        hlist.dwSize = (uint) Marshal.SizeOf(hlist);
        bool r = Heap32ListFirst(heaplist_h, ref hlist);
        while (r)
        {
        textBox1.AppendText("  flags: " + hlist.dwFlags.ToString("X") +
            ". HeapID: " + hlist.th32HeapID.ToString() + "\n");

        ToolHelp.HEAPENTRY32 heapentry = new ToolHelp.HEAPENTRY32();
        heapentry.dwSize = (uint) Marshal.SizeOf(heapentry);

        bool r2 = ToolHelp.Heap32First(ref heapentry, hlist.th32ProcessID, hlist.th32HeapID);
        while (r2)
        {
            textBox1.AppendText("    Start: " + heapentry.dwAddress.ToString() +
            ", size: " + heapentry.dwBlockSize.ToString() + "\n" );

            r2 = ToolHelp.Heap32Next(out heapentry);
        }

        r = ToolHelp.Heap32ListNext(heaplist_h, ref hlist);
        }

        ToolHelp.CloseHandle(heaplist_h);  

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions