title: Multimedia timer? <mmsystem.h>
body: <p>I'm trying to get this accurate timer working on VS2008, on Windows XP (and eventually Server 2008) from the following example:</p>
  
  <p><a href="http://technology.chtsai.org/w98timer/" rel="nofollow">http://technology.chtsai.org/w98timer/</a></p>
  
  <p>However I get the following errors:</p>
  
  <ul>
  <li>error LNK2019: unresolved external symbol _<em>imp</em>_timeEndPeriod@4</li>
  <li>error LNK2019: unresolved external symbol _<em>imp</em>_timeGetTime@0</li>
  <li>error LNK2019: unresolved external symbol _<em>imp</em>_timeBeginPeriod@4</li>
  <li>error LNK2019: unresolved external symbol _<em>imp</em>_timeGetDevCaps@8</li>
  </ul>
  
  <p>Could anybody please advise?</p>
  
  <p>I just want a simple, accurate, millisecond-timing example for C++ on Windows.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;mmsystem.h&gt;
  #include "stdafx.h"
  
  void 
  main (void)
  {
    TIMECAPS resolution;
    DWORD start, finish, duration, i;
  
    if (timeGetDevCaps (&amp;resolution, sizeof (TIMECAPS)) == TIMERR_NOERROR)
      {
        printf ("Minimum supported resolution = %d\n", resolution.wPeriodMin);
        printf ("Maximum supported resolution = %d\n", resolution.wPeriodMax);
      }
  
    if (resolution.wPeriodMin &lt;= 1)
      {
        if (timeBeginPeriod (1) == TIMERR_NOERROR)
      {
        for (i = 100; i &lt;= 120; i++)
          {
            start = timeGetTime ();
            while (timeGetTime () &lt; (start + i));
            finish = timeGetTime ();
            duration = finish - start;
            printf ("expected:%d  actual:%ld\n", i, duration);
          }
        timeEndPeriod (1);
      }
      }
  }
  </code></pre>