
Structure not found: PERFORMANCE_INFORMATION
Structure not found: PERFORMANCE_INFORMATION
I'm trying to use the PERFORMANCE_INFORMATION structure in my app, and getting an error that the structure's not found. I did a search on the forum, and found this. They posted it to the requested API structures and constants topic, but it doesn't seem to have ever been added. Either that, or it got removed at some point 

Re: Structure not found: PERFORMANCE_INFORMATION
Code: Select all
;according to this post http://forums.purebasic.com/english/viewtopic.php?p=582637,
;size_t is 8 bytes on windows and 4/8 on other os.
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Structure PERFORMANCE_INFORMATION
cb.l
CommitTotal.q
CommitLimit.q
CommitPeak.q
PhysicalTotal.q
PhysicalAvailable.q
SystemCache.q
KernelTotal.q
KernelPaged.q
KernelNonpaged.q
PageSize.q
HandleCount.l
ProcessCount.l
ThreadCount.l
EndStructure
CompilerElse
CompilerIf #PB_Compiler_64Bit
Structure PERFORMANCE_INFORMATION
cb.l
CommitTotal.q
CommitLimit.q
CommitPeak.q
PhysicalTotal.q
PhysicalAvailable.q
SystemCache.q
KernelTotal.q
KernelPaged.q
KernelNonpaged.q
PageSize.q
HandleCount.l
ProcessCount.l
ThreadCount.l
EndStructure
CompilerElse
Structure PERFORMANCE_INFORMATION
cb.l
CommitTotal.l
CommitLimit.l
CommitPeak.l
PhysicalTotal.l
PhysicalAvailable.l
SystemCache.l
KernelTotal.l
KernelPaged.l
KernelNonpaged.l
PageSize.l
HandleCount.l
ProcessCount.l
ThreadCount.l
EndStructure
CompilerEndIf
CompilerEndIf
Define ok.PERFORMANCE_INFORMATION
Debug SizeOf(ok\cb)
Debug SizeOf(ok\CommitTotal)
Re: Structure not found: PERFORMANCE_INFORMATION
Hi there,
I fiddled around this stuff used the following links and came up with this stuff below
https://learn.microsoft.com/en-us/windo ... nformation
https://learn.microsoft.com/en-us/windo ... rmanceinfo
Maybe this can be a start
I fiddled around this stuff used the following links and came up with this stuff below
https://learn.microsoft.com/en-us/windo ... nformation
https://learn.microsoft.com/en-us/windo ... rmanceinfo
Maybe this can be a start
Code: Select all
Structure PERFORMANCE_INFORMATION Align 8 ; increases the size to the needed one.
cb.l ;
CommitTotal.q ; .q is equal to .i on 64 bit (but makes it more clear to be 8 bytes long)
CommitLimit.q ;
CommitPeak.q ; size_t is ULONG_PTR
PhysicalTotal.q ;
PhysicalAvailable.q ;
SystemCache.q ;
KernelTotal.q ;
KernelPaged.q ;
KernelNonpaged.q ;
PageSize.q ;
HandleCount.l ;
ProcessCount.l ;
ThreadCount.l ;
EndStructure
Procedure ReadPerformanceInformation() ;
Protected ret, *func, pi.PERFORMANCE_INFORMATION
Debug SizeOf(pi) ; size == 112 (otherwise we got error 24 (command length incorrect)
If OpenLibrary(0, "PSAPI.DLL")
*func = GetFunction(0, "GetPerformanceInfo")
If *func
pi\cb = SizeOf(PERFORMANCE_INFORMATION)
ret = CallFunctionFast(*func, @pi, SizeOf(PERFORMANCE_INFORMATION))
If ret = 0
Debug " Error " + GetLastError_()
Else
Debug "Result "
Debug " " + pi\PhysicalTotal ; not sure this is correct, but it showed something !!!
EndIf
Else
Debug "No Function"
EndIf
CloseLibrary(0)
EndIf
ProcedureReturn ret
EndProcedure
ReadPerformanceInformation()
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Structure not found: PERFORMANCE_INFORMATION
a second way of doing (tested on a 64bit system)
Code: Select all
Structure PERFORMANCE_INFORMATION Align 8 ; size == 112 bytes
cb.l ;
CommitTotal.q ;
CommitLimit.q ;
CommitPeak.q ; size_t is ULONG_PTR
PhysicalTotal.q ;
PhysicalAvailable.q ;
SystemCache.q ;
KernelTotal.q ;
KernelPaged.q ;
KernelNonpaged.q ;
PageSize.q ;
HandleCount.l ;
ProcessCount.l ;
ThreadCount.l ;
EndStructure
Import ""
GetPerformanceInfo_(*PI.PERFORMANCE_INFORMATION, cb.l) As "K32GetPerformanceInfo"
EndImport
Procedure ReadPerformanceInformation() ;
Protected ret, *func, pi.PERFORMANCE_INFORMATION
pi\cb = SizeOf(PERFORMANCE_INFORMATION)
ret = GetPerformanceInfo_(@pi, SizeOf(PERFORMANCE_INFORMATION))
If ret = 0
Debug " Error " + GetLastError_()
Else
Debug "Result "
Debug " " + pi\PhysicalTotal
EndIf
ProcedureReturn ret
EndProcedure
ReadPerformanceInformation()
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Structure not found: PERFORMANCE_INFORMATION
Thanks all!
got it to work

Re: Structure not found: PERFORMANCE_INFORMATION
Moved to feature request, a missing API structure isn't a bug.