Laszlo wrote:
What did you see with DllCall("Sleep"..., w/o timeBeginPeriod and timeEndPeriod dll calls? If it turns out to work consistently, no need to change the Sleep command, we can just use DllCall("Sleep"... for short delays.
Without timeBeginPeriod, Sleep(1) sleeps for 15.62 ms on this Windows XP PC, which uses the ACPI multiprocessor HAL as shown in device manager.
Laszlo wrote:
Maybe it works in my case only because some other programs already set the time period to 1ms. Do you know how to tell?
Perhaps when you exit all scripts that may have called timeBeginPeriod, the OS automatically restores the normal period (even if timeEndPeriod wasn't called). If not, perhaps you could test after a fresh reboot to see if Vista's Sleep() is in fact capable of shorter durations than XP's. Some BIOS setup screens mention the fact that Vista has some kind of new support for high resolution timing.
Laszlo wrote:
I think a more precise timer is more important than a short Sleep. I tried the obsolete Winmm\timeSetEvent dll call. It works in XP and Vista, but I had mysterious crashes. Maybe someone knows the recommended CreateTimerQueueTimer method?
If timeBeginPeriod were used as the mechanism, it seems much harder to implement finer resolution in SetTimer than in Sleep because the message-processing system would have to be altered at a low level. Therefore, it would probably be better to use CreateTimerQueueTimer() or something else that generates callbacks, interrupts, or messages at very short intervals. I don't know much about this area.