2

My code:

#include <Windows.h>
#include <iostream>
#include <Pdh.h>
#pragma comment (lib, "pdh.lib")
void main()
{
    PDH_STATUS Status;
    HQUERY Query = NULL;
    HCOUNTER Counter;
    WCHAR buffer[PDH_MAX_COUNTER_PATH];
    PdhOpenQuery(NULL, NULL, &Query);
    wcscpy(buffer, L"\\NTO-PROG\Thread(_Total/_Total)\Context Switches/sec");
    Status = PdhAddEnglishCounter(Query, buffer, 0, &Counter);
}

I have this error:

pdh error

English translate:

Access point in procedure PdhAddEnglishCounterA not found in library DLL pdh.dll.

If i'm using PdhAddCounter instead of PdhAddEnglishCounter, i see in Status: 0xC0000BC0 (PDH_CSTATUS_BAD_COUNTERNAME). What I need to do with this?

p.s. I'm using Visual Studio 2010 on Windows XP.

Alexander Mashin
  • 693
  • 3
  • 14
  • 34

1 Answers1

3

The reason for your error, as MSDN says is that PdhAddEnglishCounter is not supported on Windows XP

enter image description here

For PdhAddCounter, the counter path has to be correctly localized. Refer to MSDN here. You might want to consider PdhLookupPerfNameByIndex as an alternative (again, MSDN here).

There is a useful article on the MS Knowledgebase too.

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113