By the way, to make matters worse,I need to do this for both Win98 and NT
4.0, which means I will need this coded up twice since each one has its own
structures, etc.
Thanks for any help,
Jason Phillips
jphi...@tecomac.com
if(versionInformation.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
HKEY hkey;
DWORD dwType;
DWORD result;
DWORD cbResult = 4;
if (RegOpenKey(HKEY_DYN_DATA, "PerfStats\\StatData", &hkey) ==
ERROR_SUCCESS)
{
if
RegQueryValueEx( hkey,"KERNEL\\CPUUSAGE",NULL,&dwType,(BYTE*)(&result),&cbRe
sult) == ERROR_SUCCESS)
{
if (dwType == REG_BINARY)
{
RegCloseKey(hkey);
cpuUsage = result;
}
}
RegCloseKey(hkey);
}
}
I have also been able to retrieve the "% Processor Time" counter under NT4.0
using the "Navigating the Performance Registry" example in MSDN.
Unfortunately, even though I have retrieved a counter, none of the formulas
that would make sense to use to calculate the current CPU usage seem to
work. I grab the counter data and the 100ns time value on two consecutive
requests. I then divide the counter difference by the time difference. I
always get an extremely small number ~< 0.1 as a result.
Does anyone have any suggestions?
Thanks,
Jason
NT: The source code for PerfMon is in the Platform SDK. You may want to look
at it. Also, the PDH library could be of some help. You can look up "Using
the Performance Data Helper Library" in MSDN for more information.
Hope this helps,
--Axel