Open svaarala opened 7 years ago
What's the workaround for Windows 7 builds?
@jbmonroe Could you clarify - does compilation fail for you (if so, what error)?
This is just a guess but I'm thinking he's asking for a time provider that's this precise for Windows 7. GetSystemTimePreciseAsFileTime
requires Windows 8+.
There are various approaches before GetSystemTimePreciseAsFileTime() (for some background, see https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx) but AFAIK none of them are very simple.
It would be relatively simple to use e.g. QueryPerformanceCounter() and an arbitrary starting point to get high resolution (but low accuracy) Date timestamps. While accuracy is important, sometimes it's useful to have high resolution even when the absolute accuracy is not great; this is useful for example when doing timestamp comparisons.
But even in that approach one must deal with QPC quirks, see the above link.
That said, if someone can point to a good, robust approach for pre-Windows 8, and would be willing to test it, I'd be happy to write up a pull that integrated it into the default Windows Date provider.
Actually, I just need anything that will execute without popping up a dialog that says this or that thing can't be found in Runtime32.dll (or whatever it was). Even something with a pre-compile define that says "hey, this ain't for Windows 8" since there are constraints to what I can deploy.
@jbmonroe You need to define _WIN32_WINNT appropriately sometime before windows.h gets included. Then everything should work itself out.
Okay--that's definitely good news.
As for the part where I get a stack index error of 2.1 billion when trying to add a C function? I think I'll have to work that out on my own. :)
On 28 Apr 2018, at 07:52, Sami Vaarala notifications@github.com wrote:
That said, if someone can point to a good, robust approach for pre-Windows 8, and would be willing to test it, I'd be happy to write up a pull that integrated it into the default Windows Date provider.
I have solved this by checking at runtime if GetSystemTimePreciseAsFileTime is available. If not, then the code falls back to GetSystemTime.
Here is a modified version:
DUK_INTERNAL duk_double_t duk_bi_date_get_now_windows_subms(void) { /* Variant of the basic algorithm using GetSystemTimePreciseAsFileTime()
for more accuracy. */ FILETIME ft1; SYSTEMTIME st1, st2; ULARGE_INTEGER tmp1, tmp2;
// GetSystemTimePreciseAsFileTime is only available on Windows 8 and higher typedef void (WINAPI fn_GetSystemTimePreciseAsFileTime) ( FILETIME ); static fn_GetSystemTimePreciseAsFileTime pGetSystemTimePreciseAsFileTime = NULL;; static HMODULE module = NULL;
// Check if GetSystemTimePreciseAsFileTime is available if( module == NULL ) { module = GetModuleHandle( "kernel32.dll" ); pGetSystemTimePreciseAsFileTime = (fn_GetSystemTimePreciseAsFileTime) GetProcAddress( module, "GetSystemTimePreciseAsFileTime" ); }
// If GetSystemTimePreciseAsFileTime is available, use it. Otherwise fall back to GetSystemTime if( pGetSystemTimePreciseAsFileTime ) { pGetSystemTimePreciseAsFileTime(&ft1); duk__convert_filetime_to_ularge((const FILETIME ) &ft1, &tmp1); } else { GetSystemTime(&st1); duk__convert_systime_to_ularge((const SYSTEMTIME ) &st1, &tmp1); }
dukset_systime_jan1970(&st2); dukconvert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2);
/* Difference is in 100ns units, convert to milliseconds, keeping
Kind regards,,
Pluggers Software Scholekstersingel 48 2496 MP Den Haag The Netherlands
Email: rob.laveaux@pluggers.nl mailto:rob.laveaux@pluggers.nl Website: http://www.pluggers.nl http://www.pluggers.nl/