Click to See Complete Forum and Search --> : Windows 2000 and GetProcessMemoryInfo problem


JackInMadrid
July 14th, 2006, 10:58 AM
hey
I'm getting the memory usage information for each process on a machine using psapi command 'GetProcessMemoryInfo'
This is my code:


_PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc));


When running this on Windows 2003 Server it runs no problem, but with Windows 2000 Server it fails with an error code 24 ERROR_BAD_LENGTH.

But it says on the MSDN site that _PROCESS_MEMORY_COUNTERS is supported by Windows 2000 server.

Does anyone know why this is happening, or if it's possible to get this information another way? I'm not using Visual C++.

Any help would be appreciated
Jack

Viorel
July 14th, 2006, 11:10 AM
Maybe you should initialize a member of pmc?


_PROCESS_MEMORY_COUNTERS pmc;
pmc.cb = sizeof(_PROCESS_MEMORY_COUNTERS);
GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc));

I hope it helps.

Krishnaa
July 14th, 2006, 11:12 AM
Well, your project must be assuming that target OS is above XP or something (using WINVER macros etc.)
I think the structure size varies for XP and 2003 server, try using 40 as size.

_PROCESS_MEMORY_COUNTERS pmc;
BOOL bSuccess =GetProcessMemoryInfo(hProcess, &pmc, 40);

JackInMadrid
July 14th, 2006, 12:26 PM
thanks for the replies. I can't check them now because the server I'm testing on is down until Monday. But earlier by chance I ran the program from the desktop with the original code, and it worked, but when I ran it from any other directory it failed. That is really strange to me!
Any ideas on that?
I'll try other strategies on Monday. Good weekend :)

Jack

Krishnaa
July 14th, 2006, 01:29 PM
Worked and Failed on same computer ?
You need to confirm this, I think this might be wrong reading. :)

JackInMadrid
July 17th, 2006, 03:40 AM
I've found the problem, it's stupid really. Hidden in this directory was a psapi.dll which I guess wasn't supposed to be there, may be it was a recent version not compatiple with Windows 2000. I took it out and it works now.
So GetProcessMemoryInfo does work fine on Windows 2000 as advertised.
Thanks for the time Krishnaa and Viorel
Jack.