Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.225 Beiträge
 
Delphi 12 Athens
 
#10

Re: Beschränkung von GetTickCount umgehen

  Alt 3. Dez 2007, 22:05
> CodeLib > Beschränkung von GetTickCount umgehen


Erstmal was zu Dax letztem CL-Code:
Ticks ist wärend der Zuweisung an Result in Sekundenintervallen und nicht in Millisekunden ... das Ergebnis stimmt also nicht



So und nun was Neues/Erfreuliches:
In Vista hat Microsoft sich endlich dieses Problems gewidmet und MSDN-Library durchsuchenGetTickCount64 eingeführt.

Delphi-Quellcode:
Function GetTickCount64: UInt64; StdCall;
  External 'Kernel32.dllName 'GetTickCount64';

Und das Ganze noch als nette Unit, welche auch schon früher läuft:
Delphi-Quellcode:
Unit GTCUnit;

// (c) 1997-2007 by FNS Enterprize's (FNSE.de)
// 2003-2007 by himitsu @ Delphi-PRAXiS.de
 
Interface
  Uses Windows;

  Var GetTickCount64: Function(): UInt64; StdCall;

Implementation
  Function _GetTickCount64: UInt64; StdCall;
    Var Freq, Ticks: UInt64;

    Begin
      If QueryPerformanceFrequency(Int64(Freq))
        and QueryPerformanceCounter(Int64(Ticks))
        and (Int64(Freq) > 0) Then Begin

        If Ticks >= UInt64(-1) div 1000 Then Result := Ticks div (Freq div 1000)
        Else Result := (Ticks * 1000) div Freq;
      End Else Result := 0;
    End;

Initialization
  GetTickCount64 := GetProcAddress(GetModuleHandle('Kernel32.dll'), 'GetTickCount64');
  If @GetTickCount64 = nil Then GetTickCount64 := @_GetTickCount64;

End.
Einfach Unit einbinden und GetTickCount64 wie eine normale Funktion aufrufen
Delphi-Quellcode:
Uses Windows, Unit1;

Var C, C2: UInt64;

Begin
  C := GetTickCount64;
  Sleep(3000);
  C2 := GetTickCount64;
  Label1.Caption := IntToStr(C2 - C);
End;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat