PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

About CreateToolhelp32Snapshot :(

Sorry for my noob question.

I want to write the simple application like the following link.
http://www.pocketgear.com/software_detail.asp?id=14279

I write the code to show heap size of processes, but it only show one process, don't list all process.

What's wrong with my code?

Code:

int HeapProcesslistDlg::ShowProcessSize()
{
m_list.SetColumnWidth(0, 140);
m_list.SetColumnWidth(1, 70);

hSnapShot=CreateToolhelp32Snapshot (TH32CS_SNAPALL,NULL);
HEAPENTRY32 pHeap;
pHeap.dwSize= sizeof(HEAPENTRY32);

PROCESSENTRY32 pEntry;
pEntry.dwSize =sizeof(pEntry);

DWORD dwTotal=0;
wchar_t szProcessInfo[255];

Process32First(hSnapShot,&pEntry;);
Heap32First(hSnapShot,&pHeap;,pHeap.th32ProcessID,pHeap.th32HeapID);

do
{

dwTotal += pHeap.dwBlockSize;
pHeap.dwSize= sizeof(HEAPENTRY32);

m_list.InsertItem(0,pEntry.szExeFile);
m_list.SetItemData(0,pEntry.th32ProcessID);

m_list.SetItemText(0,0,pEntry.szExeFile);
swprintf(szProcessInfo,_T("%d"),dwTotal );
m_list.SetItemText(0,1,szProcessInfo);

} while( Heap32Next(hSnapShot,&pHeap;) );

CloseToolhelp32Snapshot( hProcess );
}

Attachments:
process.JPG
temp.jpg
You keep inserting a list item into the same index: 0. You need a variable to keep track of the item index as you insert them:

int nIdx=0;

Line 28 is redundant and should be removed. Lines 25, 27 and 30 should be changed to:

Code:

m_list.InsertItem(nIdx,pEntry.szExeFile);
m_list.SetItemData(nIdx,pEntry.th32ProcessID);
...
m_list.SetItemText(nIdx++,1,szProcessInfo);


Dan East
It's also can't list all process and size.
I think my code have errors.


anyway, I found the Toolhelp32ReadProcessMemory API!
It supports WinCE! *Maybe* this API can help me.
Finally, I have finished it.

Please reference this link,and it will help you.
http://www.pocketpcdn.com/forum/viewtop ... 2listfirst