GetTickCount
The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. To obtain the system timer resolution, use the GetSystemTimeAdjustment function.
DWORD GetTickCount(VOID);
Parameters
This function has no parameters.
Return Values
The return value is the number of milliseconds that have elapsed since the system was started.
Remarks
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.
If you need a higher resolution timer, use a multimedia timer or a high-resolution timer.
Windows NT/2000: 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 Monitoring.
Example
The following example demonstrates how to handle timer wrap around.
DWORD dwStart = GetTickCount();
// Stop if this has taken too long
if( GetTickCount() - dwStart >= TIMELIMIT )
Cancel();
Where TIMELIMIT is the time interval of interest to the application.
Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
See Also
Time Overview, Time Functions