GetTickCount64 구현

3550 단어
unit uGetTickCount64;
interface
uses windows;
 function _GetTickCount64(): Int64;
implementation

type
    LARGE_INTEGER = record
      lowpart  :integer ;
      highpart :integer;
    end;
    PVOID=Pointer;
    _SYSTEM_INFORMATION_CLASS = (
        SystemBasicInformation,
        SystemProcessorInformation,
        SystemPerformanceInformation,
        SystemTimeOfDayInformation,
        SystemNotImplemented1,
        SystemProcessesAndThreadsInformation,
        SystemCallCounts,
        SystemConfigurationInformation,
        SystemProcessorTimes,
        SystemGlobalFlag,
        SystemNotImplemented2,
        SystemModuleInformation,
        SystemLockInformation,
        SystemNotImplemented3,
        SystemNotImplemented4,
        SystemNotImplemented5,
        SystemHandleInformation,
        SystemObjectInformation,
        SystemPagefileInformation,
        SystemInstructionEmulationCounts,
        SystemInvalidInfoClass1,
        SystemCacheInformation,
        SystemPoolTagInformation,
        SystemProcessorStatistics,
        SystemDpcInformation,
        SystemNotImplemented6,
        SystemLoadImage,
        SystemUnloadImage,
        SystemTimeAdjustment,
        SystemNotImplemented7,
        SystemNotImplemented8,
        SystemNotImplemented9,
        SystemCrashDumpInformation,
        SystemExceptionInformation,
        SystemCrashDumpStateInformation,
        SystemKernelDebuggerInformation,
        SystemContextSwitchInformation,
        SystemRegistryQuotaInformation,
        SystemLoadAndCallImage,
        SystemPrioritySeparation,
        SystemNotImplemented10,
        SystemNotImplemented11,
        SystemInvalidInfoClass2,
        SystemInvalidInfoClass3,
        SystemTimeZoneInformation,
        SystemLookasideInformation,
        SystemSetTimeSlipEvent,
        SystemCreateSession,
        SystemDeleteSession,
        SystemInvalidInfoClass4,
        SystemRangeStartInformation,
        SystemVerifierInformation,
        SystemAddVerifier,
        SystemSessionProcessesInformation);
    SYSTEM_INFORMATION_CLASS = _SYSTEM_INFORMATION_CLASS;
    TSystemInformationClass = SYSTEM_INFORMATION_CLASS;
    _SYSTEM_TIME_OF_DAY_INFORMATION = record // Information Class 3
        BootTime: LARGE_INTEGER;
        CurrentTime: LARGE_INTEGER;
        TimeZoneBias: LARGE_INTEGER;
        CurrentTimeZoneId: ULONG;
    end;

    SYSTEM_TIME_OF_DAY_INFORMATION = _SYSTEM_TIME_OF_DAY_INFORMATION;
    PSYSTEM_TIME_OF_DAY_INFORMATION = ^SYSTEM_TIME_OF_DAY_INFORMATION;
    function  NtQuerySystemInformation(
        SystemInformationClass: SYSTEM_INFORMATION_CLASS;
        SystemInformation: PVOID;
        SystemInformationLength: ULONG;
        ReturnLength: PULONG
        ): Integer; stdcall; external 'ntdll.dll';
function NtQuerySystemTime(
    var CurrentTime: LARGE_INTEGER
    ): Integer; stdcall; external 'ntdll.dll';

//========================================
// :_GetTickCount64
// : 
// :int64, ,   
// : delphi 7  32  windows 
// : 64 vista GetTickCount
//
function _GetTickCount64(): Int64;
var
    st: SYSTEM_TIME_OF_DAY_INFORMATION;
    r: ULONG;
    ct: LARGE_INTEGER;
    quadpart:int64 absolute ct;
    quadpart2:int64 absolute st.BootTime;
begin
   //
    NtQuerySystemInformation(SystemTimeOfDayInformation,
        @st,
        SizeOf(SYSTEM_TIME_OF_DAY_INFORMATION),
        @r);
    // , 100 
    NtQuerySystemTime(ct);
    //
    //  100,000,000   10       1000    
    Result := (QuadPart -  QuadPart2) div 10000;
end;
end.

좋은 웹페이지 즐겨찾기