Вы, , можете получить разрешение 0,5 мс с помощью скрытого API NtSetTimerResolution()
. NtSetTimerResolution экспортируется родной библиотекой NTDLL.DLL для Windows NT. См. How to set timer resolution to 0.5ms ? на MSDN. Тем не менее, истинное достижимое разрешение определяется базовым оборудованием. Современное оборудование поддерживает разрешение 0,5 мс. Более подробная информация находится в Inside Windows NT High Resolution Timers. Поддерживаемые разрешения могут быть получены вызовом NtQueryTimerResolution().
Как сделать:
#define STATUS_SUCCESS 0
#define STATUS_TIMER_RESOLUTION_NOT_SET 0xC0000245
// after loading NtSetTimerResolution from ntdll.dll:
// The requested resolution in 100 ns units:
ULONG DesiredResolution = 5000;
// Note: The supported resolutions can be obtained by a call to NtQueryTimerResolution()
ULONG CurrentResolution = 0;
// 1. Requesting a higher resolution
// Note: This call is similar to timeBeginPeriod.
// However, it to to specify the resolution in 100 ns units.
if (NtSetTimerResolution(DesiredResolution ,TRUE,&CurrentResolution) != STATUS_SUCCESS) {
// The call has failed
}
printf("CurrentResolution [100 ns units]: %d\n",CurrentResolution);
// this will show 5000 on more modern platforms (0.5ms!)
// do your stuff here at 0.5 ms timer resolution
// 2. Releasing the requested resolution
// Note: This call is similar to timeEndPeriod
switch (NtSetTimerResolution(DesiredResolution ,FALSE,&CurrentResolution) {
case STATUS_SUCCESS:
printf("The current resolution has returned to %d [100 ns units]\n",CurrentResolution);
break;
case STATUS_TIMER_RESOLUTION_NOT_SET:
printf("The requested resolution was not set\n");
// the resolution can only return to a previous value by means of FALSE
// when the current resolution was set by this application
break;
default:
// The call has failed
}
Примечание: Функциональность NtSetTImerResolution в основном преобразуются в функции timeBeginPeriod
иtimeEndPeriod
, используя булево значение Set
(см Inside Windows NT High Resolution Timers для получения более подробной информации о схеме и все его последствия). Однако мультимедийный пакет ограничивает степень детализации до миллисекунд, а NtSetTimerResolution позволяет установить значения в миллисекундах.
Вы можете посмотреть [здесь] (Http: //www.windowstimestamp/description) для получения более подробной информации о настройках таймера и услуг таймера суб миллисекунду. – Arno