AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Code-Bibliothek Library: Windows API / MS.NET Framework API Delphi Beschränkung von GetTickCount umgehen
Thema durchsuchen
Ansicht
Themen-Optionen

Beschränkung von GetTickCount umgehen

Ein Thema von Dax · begonnen am 20. Jan 2004 · letzter Beitrag vom 5. Dez 2007
Antwort Antwort
Dax
(Gast)

n/a Beiträge
 
#1

Re: Beschränkung von GetTickCount umgehen

  Alt 5. Dez 2007, 21:16
Zusätzlich hat himitsu etwas erfreuliches gemeldet: unter Vista gibt es nun GetTickCount64, also mit 64bittigem Rückgabewert statt den 32 Bit bei <=XP:
Delphi-Quellcode:
function GetTickCount64: Int64; StdCall;
  External 'Kernel32.dllName 'GetTickCount64';
Regulär ist der Rückgabewert vom Typ UInt64, was aber keinen Unterschied machen sollte und die Kompatibilität zu älteren Delphi-Versionen wahrt.

Dazu eine kleine Unit für die Funktion:
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.
Hier die Version mit UInt64, da die Unit nicht verändert, sondern direkt von himitsu übernommen wurde. Sollte das System GetTickCount64 nicht unterstützen, wird auf einen heutzutage wohl immer funktionierenden Weg über die QueryPerformance*-Funktionen zurückgegriffen.

Kleines Beispiel zur Verwendung, obwohl GetTickCount64 eine Variable ist, kann sie wie eine Funktion benutzt werden:
Delphi-Quellcode:
Uses Windows, GTCUnit;

Var C, C2: UInt64;

Begin
  C := GetTickCount64();
  Sleep(3000);
  C2 := GetTickCount64();
  Label1.Caption := IntToStr(C2 - C);
End;
  Mit Zitat antworten Zitat
Antwort Antwort

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz