Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi folks.
I am trying to get a c++ timer to work in the sort of resolution of around 10 ms.
AT the moment I am using a test loop with
int time = 40;
for(i=0; i < 30; i++)
{
a = a+1;
Sleep(time);
}The basic theory was to sample a every '40' ms.
However I am trying with the following code to give a smilar thing.
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <iostream.h>void main (void)
{
TIMECAPS resolution;
DWORD start, finish, duration, i;if (timeGetDevCaps (&resolution, sizeof (TIMECAPS)) == TIMERR_NOERROR)
{
printf ("Minimum supported resolution = %d\n", resolution.wPeriodMin);
printf ("Maximum supported resolution = %d\n", resolution.wPeriodMax);
}if (resolution.wPeriodMin <= 1)
{
if (timeBeginPeriod (1) == TIMERR_NOERROR)
{
for (i = 1; i <= 20; i++)
{
start = timeGetTime ();
while (timeGetTime () < (start + i));
finish = timeGetTime ();
printf ("start:%d finish:%ld\n", start, finish);
duration = finish - start;
printf ("expected:%d actual:%ld\n", i, duration);
}
timeEndPeriod (1);
}
}}
except I get a lot of undeclared errors for some reason.
I cannot figure out what is causing this.
I would appreciate any help.
Thanks
Elhan

use this as a timer (20000 = about 1 second depending on your processor speed):
int main(){
//stuffint time = 10000;
while (time != 0){
cout <<"_\r";
//you must have something for the computer to
//to take up time wasted otherwise there will
//no no noticable delay. This outputs an _
//nad erases it immeaditely with \r.
time--;
}//other stuff
}hope this works!
Jake

![]() |
Winsock, Firewall & P...
|
avi to vcd
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |