【发布时间】:2012-04-05 14:11:45
【问题描述】:
我正在尝试通过以下示例在 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);
}
}
}
【问题讨论】: