一种GetTickCount64实现

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.

转载于:https://my.oschina.net/u/582827/blog/337408

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值