PdhAddCounter_() - get rid of language of system?

Just starting out? Need help? Post your questions and find answers here.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

PdhAddCounter_() - get rid of language of system?

Post by registrymechanic22 »

Hi all!

for Windows with the English language:

Code: Select all

PdhAddCounter_ (hQuery, "\Process(_Total)\% Processor Time", 0, @Counter()\hCounter)
for Windows with the Russian language:

Code: Select all

PdhAddCounter_ (hQuery, "\Процессор(_Total)\% загруженности процессора", 0, @Counter()\hCounter)
for Windows with other languages:

Code: Select all

PdhAddCounter_ (hQuery, "... other languages ...", 0, @Counter()\hCounter)
How to create a universal code for Windows with all languages?
Maybe counters have some numeric identifiers or something similar?

Best regards.
fryquez
Enthusiast
Enthusiast
Posts: 370
Joined: Mon Dec 21, 2015 8:12 pm

Re: PdhAddCounter_() - get rid of language of system?

Post by fryquez »

They have an index and PdhLookupPerfNameByIndex should give you the localized name.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: PdhAddCounter_() - get rid of language of system?

Post by registrymechanic22 »

fryquez wrote:They have an index and PdhLookupPerfNameByIndex should give you the localized name.
Yes, thank you, already seen ...

Code: Select all

;PdhLookupPerfIndexByName()
PdhLookupPerfNameByIndex()
Sorry, but I can not know how to translate description MSDN on PB :( :oops: (I can only similar, following the example.)

Thanks for the help
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: PdhAddCounter_() - get rid of language of system?

Post by registrymechanic22 »

Help please, what am I doing wrong?

Code: Select all

Prototype PdhLookupPerfNameByIndex(a.s, b.l, c.s, d.l)
Global PdhLookupPerfNameByIndex.PdhLookupPerfNameByIndex
Global hQuery.l

If OpenLibrary(88, "Pdh.dll")
  PdhLookupPerfNameByIndex = GetFunction(88,"PdhLookupPerfNameByIndexA")
  Debug PdhLookupPerfNameByIndex
  
    PdhOpenQuery_ (0, 0, @hQuery)
      
    Debug "---------------"
    LPTSTR.s=Space(255)
    Debug PdhLookupPerfNameByIndex(#Null$, 238, LPTSTR, SizeOf(LPTSTR))
    Debug "---------------"
    Debug @LPTSTR
    Debug LPTSTR
EndIf
fryquez
Enthusiast
Enthusiast
Posts: 370
Joined: Mon Dec 21, 2015 8:12 pm

Re: PdhAddCounter_() - get rid of language of system?

Post by fryquez »

The last parameter is not just a long, it's the address of a long.

Code: Select all

Prototype PdhLookupPerfNameByIndex(a.s, b.l, c.s, d)
Global PdhLookupPerfNameByIndex.PdhLookupPerfNameByIndex
Global hQuery.l

If OpenLibrary(88, "Pdh.dll")
  PdhLookupPerfNameByIndex = GetFunction(88,"PdhLookupPerfNameByIndexA")
  Debug PdhLookupPerfNameByIndex
  
    PdhOpenQuery_ (0, 0, @hQuery)
      
    Debug "---------------"
    LPTSTR.s=Space(255)
    cchNameBufferSize.l = 255
    Debug PdhLookupPerfNameByIndex(#Null$, 238, LPTSTR, @cchNameBufferSize)
    Debug "---------------"
    Debug @LPTSTR
    Debug LPTSTR
EndIf
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PdhAddCounter_() - get rid of language of system?

Post by infratec »

Hi,

Code: Select all

Prototype PdhLookupPerfNameByIndex(szMachineName.s, dwNameIndex.l, *szNameBuffer, *pcchNameBufferSize)
Global PdhLookupPerfNameByIndex.PdhLookupPerfNameByIndex


Define Size.l

If OpenLibrary(88, "Pdh.dll")
  CompilerIf #PB_Compiler_Unicode
    PdhLookupPerfNameByIndex = GetFunction(88,"PdhLookupPerfNameByIndexW")
  CompilerElse
    PdhLookupPerfNameByIndex = GetFunction(88,"PdhLookupPerfNameByIndexA")
  CompilerEndIf
  
  Size = 1024
  *LPTSTR = AllocateMemory(Size)
  If *LPTSTR
    If PdhLookupPerfNameByIndex(#Null$, 238, *LPTSTR, @Size) = 0
      Debug PeekS(*LPTSTR, Size)
    EndIf
    FreeMemory(*LPTSTR)
  EndIf
EndIf
Bernd
Last edited by infratec on Fri Apr 01, 2016 11:16 am, edited 1 time in total.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: PdhAddCounter_() - get rid of language of system?

Post by registrymechanic22 »

fryquez wrote:The last parameter is not just a long, it's the address of a long.
infratec wrote: Hi
Thank you very much!

Best regards.
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: PdhAddCounter_() - get rid of language of system?

Post by Ventural »

Code: Select all

If PdhLookupPerfNameByIndex(#Null$, 238, *LPTSTR, @Size) = 0
In Purebasic 5.62 this line worked, result = 0
In Purebasic 5.70 this line failed, result = 3221228477

What changes do we need to make for this to work in 5.70?
User avatar
Bisonte
Addict
Addict
Posts: 1233
Joined: Tue Oct 09, 2007 2:15 am

Re: PdhAddCounter_() - get rid of language of system?

Post by Bisonte »

Maybe this is the ASCII / Unicode problem.

PdhLookupPerfNameByIndexA = ASCII
PdhLookupPerfNameByIndexW = Unicode
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PdhAddCounter_() - get rid of language of system?

Post by infratec »

Hi,

it looks like an error in PB 5.70
If I use:

Code: Select all

Prototype PdhLookupPerfNameByIndex(*szMachineName, dwNameIndex.l, *szNameBuffer, *pcchNameBufferSize)
and

Code: Select all

PdhLookupPerfNameByIndex(#Null, 238, *LPTSTR, @Size)
It works.

If I use

Code: Select all

Prototype PdhLookupPerfNameByIndex(szMachineName.s, dwNameIndex.l, *szNameBuffer, *pcchNameBufferSize)
and

Code: Select all

PdhLookupPerfNameByIndex(#Null$, 238, *LPTSTR, @Size)
It fails.
Desynchronised
New User
New User
Posts: 3
Joined: Mon Sep 18, 2017 7:45 pm

Re: PdhAddCounter_() - get rid of language of system?

Post by Desynchronised »

I dont think its an error in 5.70 as that parameter should be a long pointer.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PdhAddCounter_() - get rid of language of system?

Post by infratec »

Desynchronised wrote:I dont think its an error in 5.70 as that parameter should be a long pointer.
No, it's a pointer to a string.
And szMachineName.s is exactly this, because in PB a string as parameter is represented by a pointer to that string.
So it should work in PB 5.70 like in 5.62
Post Reply