一个可以再WIN2000及以上操作系统使用的GetTickCount64

转自我的旧博客

以后尽量用Delphi/C++双代码写.

GetTickCount返回值是整数,这样的话最多49天多就会复位重新从0开始.Vista以后提供了GetTickCount64这个函数, 但是WindowsXP还是主流.在项目中为了处理这个,自己实现了一套办法.这个GetTickCount和真正的额GetTickCount相比会恒 定的相差800毫秒左右.不过这个不影响使用.获取开机时间这800毫秒完全可以忽略.计算时间差的话就和GetTickCount是一样的了.

Delphi版XE下编译通过.

type
_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’;

function _GetTickCount64():Int64;
var
st : SYSTEM_TIME_OF_DAY_INFORMATION;
r : ULONG;
ct : LARGE_INTEGER;
begin
NtQuerySystemInformation(SystemTimeOfDayInformation,
@st,
SizeOf(SYSTEM_TIME_OF_DAY_INFORMATION),
@r);
NtQuerySystemTime(ct);
Result :=(ct.QuadPart-st.BootTime.QuadPart)div 10000;
end;

VC版:

typedef ULONGLONG (WINAPI GetTickCount64Proc)(void);
typedef ULONG (__stdcall * NTQUERYSYSTEMINFORMATION)(IN???? /*SYSTEM_INFORMATION_CLASS*/int, IN OUT PVOID, INT??? ULONG, OUT??? PULONG OPTION);
GetTickCount64Proc* VistaGetTickCount64 = (GetTickCount64Proc*)GetProcAddress(GetModuleHandle(_T(“kernel32.dll”)), “GetTickCount64”);

NTQUERYSYSTEMINFORMATION _NtQuerySystemInformation = (NTQUERYSYSTEMINFORMATION)GetProcAddress(GetModuleHandle(_T(“ntdll.dll”)), (“NtQuerySystemInformation”));

INT64 _GetTickCount64()
{
typedef struct _SYSTEM_TIME_OF_DAY_INFORMATION
{
LARGE_INTEGER BootTime;
LARGE_INTEGER CurrentTime;
LARGE_INTEGER TimeZoneBias;
ULONG CurrentTimeZoneId;
} SYSTEM_TIME_OF_DAY_INFORMATION, *PSYSTEM_TIME_OF_DAY_INFORMATION;
//如果系统存在VistaGetTickCount64函数则调用系统的
if (VistaGetTickCount64)
return VistaGetTickCount64();
SYSTEM_TIME_OF_DAY_INFORMATION? st ={0};
ULONG?????????????????????????? oSize = 0;
if((NULL == _NtQuerySystemInformation)||0 !=(_NtQuerySystemInformation(3, &st, sizeof(st), &oSize))||
(oSize!= sizeof(st)))
return GetTickCount();
return (st.CurrentTime.QuadPart – st.BootTime.QuadPart)/10000;
}

此条目发表在Delphi, 未分类分类目录。将固定链接加入收藏夹。

一个可以再WIN2000及以上操作系统使用的GetTickCount64》有101条回应

  1. Pingback引用通告: psixolog

  2. Pingback引用通告: psyhelp_on_line

  3. Pingback引用通告: coronavirus

  4. Pingback引用通告: PSYCHOSOCIAL

  5. Pingback引用通告: rasstanovka hellinger

  6. Pingback引用通告: Cherekasi film 2020

  7. Pingback引用通告: film doktor_liza

  8. Pingback引用通告: djoker film

  9. Pingback引用通告: viagra

  10. Pingback引用通告: t.me/psyhell

  11. Pingback引用通告: Ïñèõîëîã îíëàéí

  12. Pingback引用通告: bitly.com

  13. Pingback引用通告: viagra 100mg

  14. Pingback引用通告: viagra price

  15. Pingback引用通告: viagra online

  16. Pingback引用通告: viagra generic

  17. Pingback引用通告: viagra coupon

  18. Pingback引用通告: cheap viagra

  19. Pingback引用通告: cialis

  20. Pingback引用通告: cialis coupon

  21. Pingback引用通告: canadian pharmacy cialis

  22. Pingback引用通告: buy cialis online

  23. Pingback引用通告: bitly

  24. Pingback引用通告: movies-tekstmovies-tekst

  25. Pingback引用通告: Zemlyane 2005 smotret onlajn

  26. Pingback引用通告: smotret onlajn besplatno v kachestve hd 1080

  27. Pingback引用通告: gusmeasu.com

  28. Pingback引用通告: movies-unhinged-film

  29. Pingback引用通告: malenkie-zhenshhiny-2020

  30. Pingback引用通告: dom 2

  31. Pingback引用通告: zoom-viber-skype

  32. Pingback引用通告: Vratar Galaktiki Film, 2020

  33. Pingback引用通告: Vratar

  34. Pingback引用通告: Cherkassy 2020

  35. Pingback引用通告: chernobyl-hbo-2019-1-sezon

  36. Pingback引用通告: moskva-psiholog

  37. Pingback引用通告: batmanapollo.ru

  38. Pingback引用通告: 323

  39. Pingback引用通告: 525

  40. Pingback引用通告: dom2-ru

  41. Pingback引用通告: Tenet Online

  42. Pingback引用通告: psy psy psy psy

  43. Pingback引用通告: krsmi.ru

  44. Pingback引用通告: like-v.ru

  45. Pingback引用通告: CFOSPUK

  46. Pingback引用通告: MAMprEj

  47. Pingback引用通告: fgu0ygW

  48. Pingback引用通告: batmanapollo

  49. Pingback引用通告: tsoy

  50. Pingback引用通告: 44548

  51. Pingback引用通告: 44549

  52. Pingback引用通告: hod-korolevy-2020

  53. Pingback引用通告: HD

  54. Pingback引用通告: 158444

  55. Pingback引用通告: groznyy-serial-2020

  56. Pingback引用通告: 38QvPmk

  57. Pingback引用通告: bitly.com/eternals-online

  58. Pingback引用通告: bitly.com/maior-grom

  59. Pingback引用通告: matrica-film

  60. Pingback引用通告: dzhonuikfilm4

  61. Pingback引用通告: bitly.com/batman20212022

  62. Pingback引用通告: bitly.com/venom-2-smotret-onlajn

  63. Pingback引用通告: bitly.com/nevremyaumirat

  64. Pingback引用通告: bitly.com/kingsmankingsman

  65. Pingback引用通告: bitly.com/3zaklyatie3

  66. Pingback引用通告: bitly.com/1dreykfilm

  67. Pingback引用通告: bitly.com/topgunmavericktopgun

  68. Pingback引用通告: bitly.com/flash2022

  69. Pingback引用通告: bitly.com/fantasticheskietvari3

  70. Pingback引用通告: bitly.com/wonderwoman1984hd

  71. Pingback引用通告: Human design

  72. Pingback引用通告: 1444

  73. Pingback引用通告: cleantalkorg2.ru

  74. Pingback引用通告: 232dfsad

  75. Pingback引用通告: cleantalkorg2.ru/sitemap.xml

  76. Pingback引用通告: join vk

  77. Pingback引用通告: vk login

  78. Pingback引用通告: svaty—7—sezon

  79. Pingback引用通告: svaty 7 sezon

  80. Pingback引用通告: svaty 7

  81. Pingback引用通告: tik tok

  82. Pingback引用通告: 666

  83. Pingback引用通告: The Revenant

  84. Pingback引用通告: 00-tv.com

  85. Pingback引用通告: 2021

  86. Pingback引用通告: D4

  87. Pingback引用通告: 777

  88. Pingback引用通告: link

  89. Pingback引用通告: 4569987

  90. Pingback引用通告: news news news

  91. Pingback引用通告: psy

  92. Pingback引用通告: psy2022

  93. Pingback引用通告: projectio-freid

  94. Pingback引用通告: kinoteatrzarya.ru

  95. Pingback引用通告: topvideos

  96. Pingback引用通告: video

  97. Pingback引用通告: afisha-kinoteatrov.ru

  98. Pingback引用通告: Ukrainskie-serialy

  99. Pingback引用通告: site

  100. Pingback引用通告: top

  101. Pingback引用通告: soderzhanki-3-sezon-2021.online

评论已关闭。