0

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.

puelo
  • 5,464
  • 2
  • 34
  • 62

2 Answers2

2

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
david.jugon
  • 51
  • 1
  • 3
0

You may also want to use GetSystemTimes kernel32 API which will free you from the dependency on pdh.dll.

See my answer here.

Community
  • 1
  • 1
Arty
  • 723
  • 5
  • 10