18,356
社区成员
发帖
与我相关
我的任务
分享
#pragma comment(lib,"ntdll")
#pragma comment(lib,"user32")
#include <afxdisp.h>
#include <windows.h>
#include <winnt.h>
#include <stdio.h>
#include <memory.h>
#include <math.h>
BOOL r;
extern "C" NTSYSAPI NTAPI NtQuerySystemInformation(
IN UINT SystemInformationClass, // 信息类型
OUT PVOID SystemInformation, // 缓冲指针
IN ULONG SystemInformationLength, // 缓冲的字节大小
OUT PULONG ReturnLength OPTIONAL // 写入缓冲的字节数
);
//第一个参数是请求的信息类型。这个参数可以有许多值。为了得到系统启动时间,我们只用其中的一个值:SystemTimeInformation(3)。
//如果,第一个参数是SystemTimeInformation,则第二个参数必须是一个SYSTEM_TIME_INFORMATION结构指针。
typedef struct {
LARGE_INTEGER liKeBootTime;//系统被启动的时间(以1/10000毫秒计)。
LARGE_INTEGER liKeSystemTime;
LARGE_INTEGER liExpTimeZoneBias;
ULONG uCurrentTimeZoneId;
DWORD dwReserved;
} SYSTEM_TIME_INFORMATION;
SYSTEM_TIME_INFORMATION sti;
ULONG rl;
ULONG tk;
FILETIME ft;
//SYSTEMTIME lt;
//extern "C" ULONGLONG WINAPI GetTickCount64(void);
//ULONGLONG tk64;
ULONGLONG d497;
#define days_of_2_32ms 49.71026962962962962962962962963 //(2^32)/24/60/60/1000=49.71026962962962962962962962963
int main() {
NtQuerySystemInformation(3,&sti,sizeof(sti),&rl);//3==SystemTimeOfDayInformation
COleDateTime t,now;
CString s,fmt="%Y-%m-%d %H:%M:%S";
memcpy(&ft,&sti.liKeBootTime,sizeof(LARGE_INTEGER));
t=COleDateTime(ft);
s=t.Format(fmt);
printf(" Boot DateTime: %s\n",s);
tk=GetTickCount();//The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days.
now=COleDateTime::GetCurrentTime();
t=now-COleDateTimeSpan((double)tk/86400000.0);
s=t.Format(fmt);
printf("Prev GetTickCount() Wrap to Zero DateTime: %s\n",s);
s=now.Format(fmt);
printf(" GetTickCount():%08X,Now DateTime: %s\n",tk,s);
t=now+COleDateTimeSpan((double)(0xFFFFFFFFu-tk)/86400000.0);
s=t.Format(fmt);
printf("Next GetTickCount() Wrap to Zero DateTime: %s\n",s);
return 0;
}