Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set the timer resolution in Windows XP

650 views
Skip to first unread message

Dillon Geo

unread,
Dec 12, 2008, 11:28:47 PM12/12/08
to
Hi All,

Can we change the Windows timer (ticks) resolution from the default value
1/64 sec to, say, 1/100 sec? If yest, which API should I use?

With many thanks!
Haitao


Christian ASTOR

unread,
Dec 13, 2008, 8:48:50 AM12/13/08
to
Dillon Geo wrote:

> Can we change the Windows timer (ticks) resolution from the default value
> 1/64 sec to, say, 1/100 sec? If yest, which API should I use?

There is /TIMERES in Boot.ini
(http://technet.microsoft.com/en-us/sysinternals/bb963892.aspx)
and NtSetTimerResolution(), NtQueryTimerResolution() for process

Dillon Geo

unread,
Dec 13, 2008, 10:40:47 AM12/13/08
to
Thanks,

I read some online documentaiton aobut NtSetTimerResolution(), and cannot
figure out how to use this function. I call it in my program, and there is a
compile time error:
Error 1 error C3861: 'NtSetTimerResolution': identifier not found
I cannot find the information about this API in MSDN. How can I use this
function correctly?

"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:4943bd41$0$28669$7a62...@news.club-internet.fr...

Christian ASTOR

unread,
Dec 13, 2008, 12:37:45 PM12/13/08
to
Dillon Geo wrote:
> Thanks,
>
> I read some online documentaiton aobut NtSetTimerResolution(), and cannot
> figure out how to use this function. I call it in my program, and there is a
> compile time error:
> Error 1 error C3861: 'NtSetTimerResolution': identifier not found
> I cannot find the information about this API in MSDN. How can I use this
> function correctly?

You must call Native apis dynamically =>

typedef NTSTATUS (CALLBACK* NTSETTIMERRESOLUTION)
(
IN ULONG DesiredTime,
IN BOOLEAN SetResolution,
OUT PULONG ActualTime
);
NTSETTIMERRESOLUTION NtSetTimerResolution;

typedef NTSTATUS (CALLBACK* NTQUERYTIMERRESOLUTION)
(
OUT PULONG MaximumTime,
OUT PULONG MinimumTime,
OUT PULONG CurrentTime
);
NTQUERYTIMERRESOLUTION NtQueryTimerResolution;

HMODULE hNtDll = LoadLibrary("NtDll.dll");
if (hNtDll)
{
NtQueryTimerResolution = (NTQUERYTIMERRESOLUTION)GetProcAddress(hNtDll,
"NtQueryTimerResolution");
NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(hNtDll,
"NtSetTimerResolution");
FreeLibrary(hNtDll);
}
if (NtQueryTimerResolution == NULL || NtSetTimerResolution == NULL)
return 1
NTSTATUS nStatus;
BOOL bSetResolution = TRUE;
ULONG nActualTime;
ULONG nDesiredTime = 20064;
nStatus = NtSetTimerResolution (nDesiredTime, bSetResolution,
&nActualTime);
nStatus = NtQueryTimerResolution(&nMaximumTime, &nMinimumTime,
&nCurrentTime);

0 new messages