Reputation: 5987
i am currently trying to make some sort of CPU usage overview for my DirectX program, but it seems that i am not able to get this information through PdhAddCounter(). My code looks like this:
status = PdhOpenQuery(NULL, 0, &m_queryHandle);
if(status != ERROR_SUCCESS)
{
m_canReadCpu = false;
}
status = PdhAddCounter(m_queryHandle, TEXT("\\Processor(_Total)\\% processor time"), 0, &m_counterHandle);
if(status != ERROR_SUCCESS)
{
m_canReadCpu = false;
}
After the PdhAddCounter call my status is = -1073738824, wich causes the program to fail.
Im using a Windows 7 64bit system, do i have to make something different in a 64bit environment? Thanks for any help.
Upvotes: 0
Views: 4169
Reputation: 763
You may also want to use GetSystemTimes kernel32 API which will free you from the dependency on pdh.dll.
See my answer here.
Upvotes: 0
Reputation: 51
Remember: PdhAddCounter is locale sensible.
The response -1073738824 means PDH_CSTATUS_NO_OBJECT=0xC0000BB8. The api didn't find that string. Are you using a non-english OS?
If you need to do a Windows XP compatible application you need to use a workaround like this: http://en.verysource.com/code/3604946_1/platforminfo.cpp.html.
For Vista and Windows 7, 8,... you can use PdhAddEnglishCounter instead.
Upvotes: 2