You may try to further improve the algorithm by using QueryPerformanceXXX APIs, so you will get 64-bit up time even on most Win9x systems:History.txt wrote:02.05.18 Fixed: Use GetTickCount64 on Windows Vista or newer to show system up time >49 days (32/64)
Code: Select all
{$APPTYPE CONSOLE}
uses
Windows, SysUtils;
function GetUpTimeInMSecs : Int64;
var
GetTickCount64 : function : Int64; stdcall;
Buffer : array[0..3*SizeOf(Int64)-2] of Byte;
C, F : PInt64;
begin
GetTickCount64:=GetProcAddress(GetModuleHandle('kernel32.dll'),'GetTickCount64');
if Assigned(GetTickCount64) then
Result:=GetTickCount64
else
begin
Result:=GetTickCount;
{In some cases QueryPerformanceXXX may fail, if argument is not 8-byte aligned}
C:=@Buffer[0];
F:=@Buffer[SizeOf(C^)];
if HINST(C) mod SizeOf(C^) <> 0 then
begin
Inc(PByte(C),SizeOf(C^) - HINST(C) mod SizeOf(C^));
Inc(PByte(F),SizeOf(F^) - HINST(F) mod SizeOf(F^));
end;
if QueryPerformanceCounter(C^) and QueryPerformanceFrequency(F^) then
if F^ <> 0 then
Result:=Round(C^/F^*1000);
end;
end;
begin
Writeln('GetTickCount = '+IntToStr(GetTickCount));
Writeln('GetUpTimeInMSecs = '+IntToStr(GetUpTimeInMSecs));
Readln;
end.