1. The utility uses the function
::GetSystemTimeAdjustment
to get the intervals. And, as expected,
::SetSystemTimeAdjustment
can change the interval.
2. Using very high priorities is a very bad idea. You can lock your complete system. You may use
::QueryPerformanceCounter
to measure time spans with higher resolutions. There are some articles here at CodeProject about the Performance Counter.
3. If you only want to measure times, using
::QueryPerformanceCounter
may solve your problem. If you need some kind of action after a specific very short time, things are more complicated.
EDIT:
I must correct my answer to the first item.
::GetSystemTimeAdjustment
can be only used to get the current timer interval and
::SetSystemTimeAdjustment
can't be used to set it. To get also the min. and max. values and change the interval, the undocumented functions
NtQueryTimerResolution()
and
NtSetTimerResolution()
can be used. These functions have no associated import library. Use
GetModuleHandle()
and
GetProcAddress()
to dynamically link to
Ntdll.dll.
GetModuleHandle()
can be used rather than
LoadLibrary()
because
Ntdll.dll has been loaded by the app:
typedef NTSTATUS (CALLBACK* LPFN_NtQueryTimerResolution)(PULONG,PULONG,PULONG);
typedef NTSTATUS (CALLBACK* LPFN_NtSetTimerResolution)(ULONG,BOOLEAN,PULONG);
HMODULE hNtDll = ::GetModuleHandle(_T("Ntdll"));
if (hNtDll)
{
ULONG nMinRes, nMaxRes, nCurRes;
LPFN_NtQueryTimerResolution pQueryResolution =
(LPFN_NtQueryTimerResolution)::GetProcAddress(hNtDll, "NtQueryTimerResolution");
if (pQueryResolution &&
pQueryResolution(&nMinRes, &nMaxRes, &nCurRes) == STATUS_SUCCESS)
{
TRACE(_T("NT timer resolutions (min/max/cur): %u.%u / %u.%u / %u.%u ms"),
nMinRes / 10000, (nMinRes % 10000) / 10,
nMaxRes / 10000, (nMaxRes % 10000) / 10,
nCurRes / 10000, (nCurRes % 10000) / 10);
}
LPFN_NtSetTimerResolution pSetResolution =
(LPFN_NtSetTimerResolution)::GetProcAddress(hNtDll, "NtSetTimerResolution");
if (pSetResolution && nSetRes)
{
NTSTATUS nStatus = pSetResolution(nSetRes, TRUE, &nCurRes);
}
}