09-27-2022, 01:50 PM
(This post was last modified: 09-27-2022, 02:06 PM by SpriggsySpriggs.
Edit Reason: good grief, forgot a function
)
Eh, what the heck. I decided to go ahead and do it for ya. Here is the MEM.H file converted to 100% BAS code.
Everything should work just the same since all the variable types match and the structs are the proper size.
EDIT: It should be good now. Had a function missing.
Everything should work just the same since all the variable types match and the structs are the proper size.
Code: (Select All)
Type MEMORYSTATUSEX
As _Unsigned Long dwLength, dwMemoryLoad
As _Unsigned _Integer64 ullTotalPhys, ullAvailPhys, ullTotalPageFile, ullAvailPageFile, ullTotalVirtual, ullAvailVirtual, ullAvailExtendedVirtual
End Type
Type FILETIME
As _Unsigned Long dwLowDateTime, dwHighDateTime
End Type
Declare CustomType Library
Sub GlobalMemoryStatusEx (ByVal lpBuffer As _Offset)
Function GetSystemTimes& (ByVal lpIdleTime As _Offset, Byval lpKernelTime As _Offset, Byval lpUserTime As _Offset)
End Declare
Function MemInUsePercent~& () 'I changed this one to a return of _Unsigned Long because dwMemoryLoad is an _Unsigned Long. I think Steve had missed that originally
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
MemInUsePercent = statex.dwMemoryLoad
End Function
Function TotalPhysicalMem~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
TotalPhysicalMem = statex.ullTotalPhys
End Function
Function FreePhysicalMem~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
FreePhysicalMem = statex.ullAvailPhys
End Function
Function TotalPagingFile~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
TotalPagingFile = statex.ullTotalPageFile
End Function
Function FreePagingFile~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
FreePagingFile = statex.ullAvailPageFile
End Function
Function TotalVirtualMem~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
TotalVirtualMem = statex.ullTotalVirtual
End Function
Function FreeVirtualMem~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
FreeVirtualMem = statex.ullAvailVirtual
End Function
Function FreeExtendedMem~&& ()
Dim As MEMORYSTATUSEX statex
statex.dwLength = Len(statex)
GlobalMemoryStatusEx _Offset(statex)
FreeExtendedMem = statex.ullAvailExtendedVirtual
End Function
Function CalculateCPULoad! (idleTicks As _Unsigned _Integer64, totalTicks As _Unsigned _Integer64) Static
Static As _Unsigned _Integer64 previousTotalTicks, previousIdleTicks
Dim As _Unsigned _Integer64 totalTicksSinceLastTime: totalTicksSinceLastTime = totalTicks - previousTotalTicks
Dim As _Unsigned _Integer64 idleTicksSinceLastTime: idleTicksSinceLastTime = idleTicks - previousIdleTicks
Dim As Single ret
If totalTicksSinceLastTime > 0 Then ret = 1.0 - idleTicksSinceLastTime / totalTicksSinceLastTime Else ret = 0
previousTotalTicks = totalTicks
previousIdleTicks = idleTicks
CalculateCPULoad = ret
End Function
Function FileTimeToInt64~&& (ft As FILETIME) Static
FileTimeToInt64 = _ShL(ft.dwHighDateTime, 32) Or ft.dwLowDateTime
End Function
Function GetCPULoad! ()
Dim As FILETIME idleTime, kernelTime, userTime
If GetSystemTimes(_Offset(idleTime), _Offset(kernelTime), _Offset(userTime)) Then GetCPULoad = CalculateCPULoad(FileTimeToInt64(idleTime), FileTimeToInt64(kernelTime) + FileTimeToInt64(userTime)) Else GetCPULoad = -1.0
End Function
EDIT: It should be good now. Had a function missing.
Ask me about Windows API and maybe some Linux stuff