24 out of 51 rated this helpful Rate this topic

GetTickCount function

Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.

Syntax

DWORD WINAPI GetTickCount(void);

Parameters

This function has no parameters.

Return value

The return value is the number of milliseconds that have elapsed since the system was started.

Remarks

The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds. The resolution of the GetTickCount function is not affected by adjustments made by the GetSystemTimeAdjustment function.

The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. To avoid this problem, use the GetTickCount64 function. Otherwise, check for an overflow condition when comparing times.

If you need a higher resolution timer, use a multimedia timer or a high-resolution timer.

To obtain the time elapsed since the computer was started, retrieve the System Up Time counter in the performance data in the registry key HKEY_PERFORMANCE_DATA. The value returned is an 8-byte value. For more information, see Performance Counters.

To obtain the time the system has spent in the working state since it was started, use the QueryUnbiasedInterruptTime function.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Time Functions
Windows Time

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
not very precise
NB that even in windows 7 this has only precision of 0.015s $0Also another slightly more precise option is GetSystemTimeAsFileTime$0 $0which in windows 7 is microsecond precision, in windows XP is 0.015s precision.$0
Confusing statment about GetTickCount resolution adjustment
This is a very confusing statement
"The resolution of the GetTickCount function is not affected by adjustments made by the GetSystemTimeAdjustment function."
The GetSystemTimeAdjustment does not adjust the time to counter for lag (either explicitly if provided by the programmer) or through synchronizing to some external source.
Also the Set/GetSystemTimeAdjustment does not change the resolution it only adjust for the drift.
Does the GetTickcount lags behind the systemtime (which is adjusted either every interval if SetSystemTimeAdjustment is enabled or by the system periodically which cause the jumps in the system time reported after the system adjusting the time with some external source)? If it does, does this mean the GetTickcount just adds the system time interrupt interval to this counter (on every clock interrupt). (e.g gettickcount is not adjusted for lag and will lag behind the system time delta taken from boot time)

Thanks.
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern int GetTickCount();
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetTickCount() As Integer
End Function