views:

133

answers:

1

Hello,

I need to measure all used GDI objects in a Windows xp system. I found a GetGuiResources(__in HANDLE hProcess, __in DWORD uiFlags) method (with the GR_GDIOBJECTS flag). I call it for the process which I get from the method GetCurrentProcess() defined in WinBase.h.

I don't know how to call it for other system processes, which I get by System::Diagnostics::Process::GetProcesses(), because that function returns an array of Process pointers, and GetGuiResources takes a HANDLE.

Does anybody know a solution for that? How can I transform Process pointer to a Handle or get HANDLEs for all running system processes?

thanks for help in advance!

A: 

Using the Id property of each Process object of the array returned by GetProcesses() you can get the ID of each process. Then, from an ID, you can get a handle via the OpenProcess API. Remember to close the handle with CloseHandle when you don't need it anymore.

Note that you can't use the Handle property of the Process objects, because it works only for the objects returned by Process.Start.

By the way, keep in mind that for new projects you should use the new C++/CLI language instead of the old Managed C++ extensions.

Matteo Italia