Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: Alhexx on 2002-07-03 18:34:29

Title: Getting System Info via Win API
Post by: Alhexx on 2002-07-03 18:34:29
I'm trying to show the current memory/CPU usage in a C++ App like the Windows Task Manager in WinNT systems do. However, I can't find any useful API calls to read out those values.

Does anyone know where to get them?

 - Alhexx
Title: Getting System Info via Win API
Post by: ficedula on 2002-07-03 19:13:29
Memory usage, there's a single API call thats something like "GetGlobalMemoryStatus" IIRC (haven't got my docs to hand). CPU usage  I suspect you need to delve into performance statistics, which aren't *quite* so simple (I've never actually done that myself).
Title: Getting System Info via Win API
Post by: phaeron on 2002-07-04 02:13:24
CPU usage is tricky -- under Windows NT, you can get your own process's memory usage with GetProcessTimes() and GetThreadTimes(), but I don't know how to read the global CPU usage yet since I haven't been able to get a usable process or thread handle for the idle process.  Get*Times() doesn't work under Windows 95/98, but you can get the global CPU usage from the registry.  See oshelper.cpp in the VirtualDub source code for ways to measure CPU usage under both NT and 9x.

It is possible to measure per-thread CPU usage under 9x, but it's difficult -- the KernelToy WinTop does it by loading a special VxD that activates on context switches.
Title: Getting System Info via Win API
Post by: Alhexx on 2002-07-04 11:54:05
Okay, I'll try that out...

thanx

 - Alhexx
Title: Getting System Info via Win API
Post by: mirex on 2002-07-04 12:00:07
Im new at this process thingies, but as i look at the help, how about to get handle to idle process by OpenProcess() with id 0, (that should be idle one) and then GetProcessTimes() with this handle ?
  just a thought.
Title: Getting System Info via Win API
Post by: phaeron on 2002-07-04 21:09:55
I've never gotten it to work -- OpenProcess() always returns NULL, even with Administrator privileges.  Might need some NT security mojo.
Title: Getting System Info via Win API
Post by: Alhexx on 2002-07-05 16:21:18
Okay, I don't care 'bout the CPU usage atthe moment, but I read out the memory usage via GetProcessMemoryInfo(). However, it uses the "psapi.dll" which is only implemented on WinNT systems.
What do you think, would my app also work on Win9x systems if I deliver the psapi.dll together with my app?

 - Alhexx
Title: Getting System Info via Win API
Post by: Qhimm on 2002-07-05 20:02:08
Perhaps. Generally it's a bad idea to include system DLLs from specific OS's with your program, though. Either find a work-around that works on Win9x (not sure if Win9x can even measure process memory usage...), or exclude that functionality in Win9x programmatically (dynamic linking). Might not be what you want, though ;-)
Title: Getting System Info via Win API
Post by: Alhexx on 2002-07-06 09:04:47
I think the easiest way to find it out is to try it out. Kaoru has got Win98 installed on his machine - I'll try it before releasing Ultima 0.31 ...

 - Alhexx
Title: Getting System Info via Win API
Post by: mirex on 2002-07-06 13:40:13
I tried to copy a dinput8.dll to my program (which was messing with joystick) on the computer without directx installed. It didn't work.
Title: Getting System Info via Win API
Post by: Alhexx on 2002-07-07 16:12:14
Okay, I've tried it out - it doesn't work ... I've gotta find another solution...

 - Alhexx