Page 1 of 1
					
				PdhAddCounter_() - get rid of language of system?
				Posted: Thu Mar 31, 2016 8:00 am
				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.
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Thu Mar 31, 2016 10:30 am
				by fryquez
				They have an index and PdhLookupPerfNameByIndex should give you the localized name.
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Thu Mar 31, 2016 11:31 am
				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   
  
     (I can only similar, following the example.)
Thanks for the help
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Fri Apr 01, 2016 9:09 am
				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
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Fri Apr 01, 2016 10:21 am
				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
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Fri Apr 01, 2016 10:24 am
				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
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Fri Apr 01, 2016 10:51 am
				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.
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Sun Jan 13, 2019 4:33 am
				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?
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Sun Jan 13, 2019 11:59 am
				by Bisonte
				Maybe this is the ASCII / Unicode problem.
PdhLookupPerfNameByIndexA = ASCII
PdhLookupPerfNameByIndexW = Unicode
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Sun Jan 13, 2019 4:08 pm
				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.
 
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Sun Jan 13, 2019 5:08 pm
				by Desynchronised
				I dont think its an error in 5.70 as that parameter should be a long pointer.
			 
			
					
				Re: PdhAddCounter_() - get rid of language of system?
				Posted: Sun Jan 13, 2019 6:10 pm
				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