Just a guess here, but try setting resolution to a smaller number. You could try zero to see if that helps, then try larger values. Without a call to timeBeginPeriod(), I'm wondering if the timer just runs at the default tick rate, which is 15.625 ms (64hz), despite the resolution parameter passed to timeSetEvent(). Some really old example C code to check if 1ms timer is really 1ms (it's not on Windows XP, which runs at 1024hz with occasional double ticks to average 1000hz, it is 1ms on Windows 7 and later, and I don't know about Windows Vista).
Code:
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "winmm.lib") /* include winmm.lib */
/*----------------------------------------------------------------------*/
/* data */
/*----------------------------------------------------------------------*/
static TIMECAPS sTimeCaps; /* min and max timer values */
static MMRESULT mmrTimerId; /* timer id */
static volatile DWORD dwTicks = (0-1); /* tick counter */
static LARGE_INTEGER liPerfFrequency; /* 64 bit frequency */
static LARGE_INTEGER liDecFrequency; /* decimal frequency */
static volatile LARGE_INTEGER aliPerfCount[1032]; /* 64 bit query counts */
static double dDeltams; /* elapsed time in ms */
/*----------------------------------------------------------------------*/
/* code */
/*----------------------------------------------------------------------*/
void CALLBACK TimerFunction(UINT, UINT, DWORD, DWORD, DWORD);
/*----------------------------------------------------------------------*/
/* main */
/*----------------------------------------------------------------------*/
int main(int argc, char **argv)
{
int i;
/* ** get min and max period */
timeGetDevCaps(&sTimeCaps, sizeof(sTimeCaps));
if(sTimeCaps.wPeriodMin != 1){
printf("1 ms resolution not allowed\n");
goto exit1;}
QueryPerformanceFrequency(&liPerfFrequency);
timeBeginPeriod(1); /* set period to 1ms */
Sleep(128); /* wait for it to stabilize */
/* ** create 1ms timer to set event */
mmrTimerId = timeSetEvent(1, 0, TimerFunction, 0, TIME_PERIODIC);
if(mmrTimerId == (MMRESULT)0){
printf("Failed to generate multimedia timer.\n");
goto exit0;}
Sleep(2048); /* wait for counts to get stored */
timeKillEvent(mmrTimerId); /* stop the timer */
for(i = 0; i < 1024; i++){
dDeltams = (double)(aliPerfCount[i+1].QuadPart - aliPerfCount[i].QuadPart) * 1000. /
(double)(liPerfFrequency.QuadPart);
printf("%8.4lf", dDeltams);
if((i&7) == 7)
printf("\n");
}
dDeltams = (double)(aliPerfCount[1024].QuadPart - aliPerfCount[0].QuadPart) * 1000. /
(double)(liPerfFrequency.QuadPart);
printf("%16.4lf\n", dDeltams);
exit0:
timeEndPeriod(1); /* restore resolution to default */
exit1:
return(0);
}
/*----------------------------------------------------------------------*/
/* TimerFunction increments dwTicks */
/*----------------------------------------------------------------------*/
void CALLBACK TimerFunction(UINT uTimerID, UINT uMsg,
DWORD dwUser, DWORD dw1, DWORD dw2)
{
dwTicks += 1; /* increment ticks */
if(dwTicks < 1032) /* store count */
QueryPerformanceCounter((PLARGE_INTEGER)&aliPerfCount[dwTicks]);
}