Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if GetSystemTimePreciseAsFileTime() is available and fallback to GetSystemTimeAsFileTime() #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion source/c/astronomy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,24 @@ astro_time_t Astronomy_CurrentTime(void)
FILETIME ft;
ULARGE_INTEGER large;
/* Get time in 100-nanosecond units from January 1, 1601. */
GetSystemTimePreciseAsFileTime(&ft);
/* GetSystemTimePreciseAsFileTime is only available since Windows 8 */
typedef void (WINAPI *GetSystemTimePreciseAsFileTimeFunc)(LPFILETIME);
GetSystemTimePreciseAsFileTimeFunc pGetSystemTimePreciseAsFileTime = NULL;
HMODULE hModule = GetModuleHandleA("kernel32.dll");
if (hModule) {
union {
FARPROC proc;
GetSystemTimePreciseAsFileTimeFunc func;
} converter;
converter.proc = GetProcAddress(hModule, "GetSystemTimePreciseAsFileTime");
pGetSystemTimePreciseAsFileTime = converter.func;
}
// Use the function if available, otherwise fallback
if (pGetSystemTimePreciseAsFileTime) {
pGetSystemTimePreciseAsFileTime(&ft);
} else {
GetSystemTimeAsFileTime(&ft);
}
large.u.LowPart = ft.dwLowDateTime;
large.u.HighPart = ft.dwHighDateTime;
sec = (large.QuadPart - 116444736000000000ULL) / 1.0e+7;
Expand Down