LclIntf.GetTickCount64() calls Windows.GetTickCount() which has 32 bit result
Original Reporter info from Mantis: jk987
-
Reporter name:
Original Reporter info from Mantis: jk987
- Reporter name:
Description:
In Delphi on 32 bit Windows XP I was solving non-existence of GetTickCount64() so I was wondering how in Lazarus is it done. And I found out that Lazarus in inside its GetTickCount64() calls Windows.GetTickCount() which returns only DWORD.
I'm not the only one who has this problem, see:
http://forum.lazarus.freepascal.org/index.php?topic=30424.0
I ended up using something like this:
http://www.delphipraxis.net/711170-post5.html
My code, works both in Delphi and in Lazarus:
uses Windows;
type TGetTickCount64 = function(): Int64; stdcall;
var GetTickCount64: TGetTickCount64;
function _GetTickCount64: Int64; StdCall;
var
freq, ticks, maxTicks: Int64;
begin
maxTicks := Int64(-1) shr 11; /// ticks*1000 might overflow, 1000 is about 2^10.
if QueryPerformanceFrequency(freq) and QueryPerformanceCounter(ticks) and (freq > 0) then begin
if ticks >= maxTicks then
Result := (ticks div freq) * 1000
else
Result := (ticks * 1000) div freq;
end else
Result := Windows.GetTickCount(); /// 32 bit!
end;
initialization
GetTickCount64 := TGetTickCount64(GetProcAddress(GetModuleHandle('Kernel32.dll'), 'GetTickCount64'));
if (@GetTickCount64 = nil) then GetTickCount64 := @_GetTickCount64;
end.
Mantis conversion info:
- Mantis ID: 30927
- OS: Win7
- OS Build: 64bit
- Platform: Windows
- Version: 1.6
- Fixed in revision: 53364 (#37928d11)