New and improved SICK project
#6
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.

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
Reply


Messages In This Thread
New and improved SICK project - by eoredson - 09-20-2022, 04:44 AM
RE: New and improved SICK project - by mnrvovrfc - 09-24-2022, 02:52 AM
RE: New and improved SICK project - by mnrvovrfc - 09-24-2022, 08:06 PM
RE: New and improved SICK project - by eoredson - 09-27-2022, 06:21 AM
RE: New and improved SICK project - by SpriggsySpriggs - 09-27-2022, 01:50 PM
RE: New and improved SICK project - by eoredson - 09-28-2022, 03:11 AM
RE: New and improved SICK project - by mnrvovrfc - 09-28-2022, 04:39 AM
RE: New and improved SICK project - by eoredson - 09-28-2022, 05:03 AM
RE: New and improved SICK project - by mnrvovrfc - 10-06-2022, 11:34 PM
RE: New and improved SICK project - by mnrvovrfc - 09-28-2022, 07:02 PM
RE: New and improved SICK project - by Pete - 09-28-2022, 03:48 PM
RE: New and improved SICK project - by aurel - 09-28-2022, 09:34 PM
RE: New and improved SICK project - by eoredson - 09-29-2022, 04:45 AM
RE: New and improved SICK project - by Pete - 09-28-2022, 09:46 PM
RE: New and improved SICK project - by mnrvovrfc - 09-30-2022, 04:25 PM
RE: New and improved SICK project - by eoredson - 10-01-2022, 02:30 AM
RE: New and improved SICK project - by eoredson - 10-01-2022, 03:58 AM
RE: New and improved SICK project - by mnrvovrfc - 10-04-2022, 02:20 PM
RE: New and improved SICK project - by eoredson - 10-06-2022, 12:44 AM
RE: New and improved SICK project - by mnrvovrfc - 10-06-2022, 05:12 AM
RE: New and improved SICK project - by aurel - 10-06-2022, 07:09 PM
RE: New and improved SICK project - by mnrvovrfc - 10-06-2022, 08:05 PM
RE: New and improved SICK project - by bplus - 10-06-2022, 07:46 PM
RE: New and improved SICK project - by aurel - 10-07-2022, 11:39 AM
RE: New and improved SICK project - by aurel - 10-07-2022, 12:00 PM
RE: New and improved SICK project - by mnrvovrfc - 10-07-2022, 11:41 PM
RE: New and improved SICK project - by mnrvovrfc - 10-12-2022, 05:19 PM
RE: New and improved SICK project - by eoredson - 10-21-2022, 03:15 AM
RE: New and improved SICK project - by mnrvovrfc - 10-21-2022, 07:03 AM
RE: New and improved SICK project - by eoredson - 03-11-2023, 04:34 AM
RE: New and improved SICK project - by eoredson - 04-07-2023, 03:52 AM



Users browsing this thread: 15 Guest(s)