#pragma comment(lib, "ntdll.lib")
#include <Windows.h>
#include <winternl.h>
#define SystemTimeOfDayInformation 3
typedef struct _SYS_TIMEOFDAY_INFO {
LARGE_INTEGER BootTime;
LARGE_INTEGER CurrentTime;
LARGE_INTEGER TimeZoneBias;
ULONG TimeZoneId;
ULONG Reserved;
ULONGLONG BootTimeBias;
ULONGLONG SleepTimeBias;
} SYS_TIMEOFDAY_INFO, *PSYS_TIMEOFDAY_INFO;
BOOL GetCrntTime(PLARGE_INTEGER crntTime)
{
LARGE_INTEGER ret;
SYS_TIMEOFDAY_INFO sysTimeInfo;
ULONG cbNeeded = sizeof(sysTimeInfo);
if (NT_SUCCESS(NtQuerySystemInformation(SystemTimeOfDayInformation, &sysTimeInfo, cbNeeded, &cbNeeded)))
{
*crntTime = sysTimeInfo.CurrentTime;
return TRUE;
}
else return FALSE;
}
// Alternative Ways to get system time
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
FILETIME fileTime;
SYSTEMTIME sysTime,t2;
//Method1: Kernel32
//GetSystemTimeAsFileTime(&fileTime);
//Method2 : ntdll
//NtQuerySystemTime(&fileTime);
//Method3 : ntdll
GetCrntTime(&fileTime);
FileTimeToSystemTime(&fileTime, &sysTime);
return 0;
}
Please Vote this post if you like it.
Please Follow me if you like my posts.
If you have any questions about this post, ask in comments.
Follow me on :
DTube
Congratulations @ntstatus! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
Your next target is to reach 20 posts.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
To support your work, I also upvoted your post!
Check out the last post from @hivebuzz: