我试图让这个准确的计时器在 VS2008、Windows XP(最终是 Server 2008)上从以下示例中运行:
http://technology.chtsai.org/w98timer/
但是我收到以下错误:
- 错误 LNK2019:未解析的外部符号 _ imp _timeEndPeriod@4
- 错误 LNK2019:未解析的外部符号 _ imp _timeGetTime@0
- 错误 LNK2019:未解析的外部符号_imp _timeBeginPeriod @4
- 错误 LNK2019:无法解析的外部符号 _ imp _timeGetDevCaps@8
有人可以建议吗?
我只想在 Windows 上为 C++ 提供一个简单、准确、毫秒计时的示例。
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include "stdafx.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 = 100; i <= 120; i++)
{
start = timeGetTime ();
while (timeGetTime () < (start + i));
finish = timeGetTime ();
duration = finish - start;
printf ("expected:%d actual:%ld\n", i, duration);
}
timeEndPeriod (1);
}
}
}