CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    I'm just speaking theoretical here, because I never used the pdh functions in depth, but ...

    Are you working with a localized version of Windows (not English) ?

    In that case, what happens to the names of the objects, might they be translated to the lcoalized language too ? I mean "Processor" and "% Processor Time". At least PerfMon shows them to me in my german Windows version with the german names (in the object list ...)

  2. #17
    Join Date
    Feb 2004
    Location
    RB(The Republic of Belarus)
    Posts
    12
    PerfMon on my Win2k works correctly.
    But... I have a rus Windows version... so the name of a counter is russian. But I don't think that problem is in such way...
    So the whole name is \\NAME_OF_MY_MACHINE\Ïðîöåññîð(_Total)\% ç*ãðóæå**îñòè ïðîöåññîð*

  3. #18
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    At least I don't hope so... as I said, just a theoretical question to be sure since I don't see any other failures in your code ... and I saw perfmon reporting me object names in german on my Windows version.



    I asked before and perhaps I missed the answer, but... Do you build your application as Unicode ?

  4. #19
    Join Date
    Feb 2004
    Location
    RB(The Republic of Belarus)
    Posts
    12
    I don't know but.. may be problem whith szMachineName or dwInstanceIndex..?

  5. #20
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by Punga
    PerfMon on my Win2k works correctly.
    But... I have a rus Windows version... so the name of a counter is russian. But I don't think that problem is in such way...
    So the whole name is \\NAME_OF_MY_MACHINE\Ïðîöåññîð(_Total)\% ç*ãðóæå**îñòè ïðîöåññîð*
    Actually I do think that is the problem, the lookup is done in the registry, though the below states it also stores the english version also, perhaps it's a trump because of the locale. Convert the counter name to what you posted above and use that. I've only used english for the PdhXXX functions. Here is msdn's link to surf around on.

    http://msdn.microsoft.com/library/de...addcounter.asp

    Retrieving Counter Names and Explanations
    Object type names, counter names, object explanations, and counter explanations are not made directly available in the performance data structures. Instead, the performance data structures contain indexes you can use to locate where the names and explanations for each object and counter can be found. The ObjectNameTitleIndex and ObjectHelpTitleIndex members of the PERF_OBJECT_TYPE structure contain the indexes to the object name and explanation, respectively. The CounterNameTitleIndex and CounterHelpTitleIndex members of the PERF_COUNTER_DEFINITION structure contain the indexes to the counter name and explanation, respectively.

    To access the names and explanations, read the Counter and Help values in the following registry key.

    HKEY_LOCAL_MACHINE\
    SOFTWARE\
    Microsoft\
    Windows NT\
    CurrentVersion\
    Perflib\
    langid

    The langid is the ASCII representation of the 3-digit hexadecimal language identifier. For example, the U.S. English langid is 009. In a non-English version of Windows, counters are stored in both the native language of the system and in English.


    Why is it everyone can't just use english and eat at McDonalds

    /Promoting the american stereotype...

  6. #21
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    Sorry to tell you that (and I can't tell that this is fine), but:

    1) I tried your code sniplet and it didn't work for me
    2) I changed the names to the german translations and it worked ...

    PDH_STATUS pdhResult = 0;
    TCHAR szCounterPath[1024];
    DWORD dwPathSize = 1024;
    PDH_COUNTER_PATH_ELEMENTS pe;
    HQUERY hQuery;
    HQUERY hCounter;
    pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
    pe.szMachineName = 0l;
    pe.szObjectName = "Prozessor";
    pe.szInstanceName = "_Total";
    pe.szParentInstance = NULL;
    pe.dwInstanceIndex = 0;
    pe.szCounterName = "Prozessorzeit (%)";
    pdhResult = PdhMakeCounterPath(&pe, szCounterPath, &dwPathSize, 0);
    pdhResult = PdhAddCounter(hQuery, szCounterPath, 0, &hCounter);


    So you have to try the russian equivalents (sorry, or is there a difference between russian and white-russian / belaruss ? Im not sure, I should know that living here not to far away from you, but I have to admit I don't) and I think you have to use unicode for that.
    Last edited by Marco F; April 12th, 2004 at 05:20 PM.

  7. #22
    Join Date
    Feb 2004
    Location
    RB(The Republic of Belarus)
    Posts
    12
    I need to build my application as Unicode ? Tell me plz how to do this And how should I write names of PDH_COUNTER_PATH_ELEMENTS structure elements, whith _T(...) or not ?

  8. #23
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by Marco F
    Sorry to tell you that (and I can't tell that this is fine), but:

    1) I tried your code sniplet and it didn't work for me
    2) I changed the names to the german translations and it worked ...

    PDH_STATUS pdhResult = 0;
    TCHAR szCounterPath[1024];
    DWORD dwPathSize = 1024;
    PDH_COUNTER_PATH_ELEMENTS pe;
    HQUERY hQuery;
    HQUERY hCounter;
    pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
    pe.szMachineName = 0l;
    pe.szObjectName = "Prozessor";
    pe.szInstanceName = "_Total";
    pe.szParentInstance = NULL;
    pe.dwInstanceIndex = 0;
    pe.szCounterName = "Prozessorzeit (%)";
    pdhResult = PdhMakeCounterPath(&pe, szCounterPath, &dwPathSize, 0);
    pdhResult = PdhAddCounter(hQuery, szCounterPath, 0, &hCounter);


    So you have to try the russian equivalents (sorry, or is there a difference between russian and white-russian / belaruss ? Im not sure, I should know that living here not to far away from you, but I have to admit I don't) and I think you have to use unicode for that.
    That is why on my previous posts I kept asking for him to run perfmon and look at the counter name.

  9. #24
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    I think you must use unicode or at least you ave to explizitlly call the UNICODE-version of the pdh-functions. I think your russian characters are not in the "standard-Ansi" range, but you should know that better than me.

  10. #25
    Join Date
    Feb 2004
    Location
    RB(The Republic of Belarus)
    Posts
    12
    But the program won't work under the eng. version Win2k... Or I mistake?

  11. #26
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    Forcing Unicode-PDH-Functions:
    =========================
    PDH_STATUS pdhResult = 0;
    wchar_t szCounterPath[1024];
    DWORD dwPathSize = 1024;
    PDH_COUNTER_PATH_ELEMENTS_W pe;
    HQUERY hQuery;
    HQUERY hCounter;
    pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
    pe.szMachineName = 0l;
    pe.szObjectName = L"Prozessor";
    pe.szInstanceName = L"_Total";
    pe.szParentInstance = NULL;
    pe.dwInstanceIndex = 0;
    pe.szCounterName = L"Prozessorzeit (%)";
    pdhResult = PdhMakeCounterPathW(&pe, szCounterPath, &dwPathSize, 0);
    pdhResult = PdhAddCounterW(hQuery, szCounterPath, 0, &hCounter);


    ===================

    yes, the program will not work in ANY W2K version different from russian. Sorry, I don't know a better way. Perhaps there is one, but I don't know.

    Only thing you could do is to localize the strings via a string table for your different target locales.

  12. #27
    Join Date
    May 2002
    Posts
    52
    Use my sample which helps you getting cpu usage for whole system or for a single process:
    How to get CPU usage by performance counters (without PDH)

  13. #28
    Join Date
    Feb 2004
    Location
    RB(The Republic of Belarus)
    Posts
    12
    -->> dudiav
    I can't extract the downloaded archive *.zip.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured