|
- #include
- #include
- # define ONE_MILLI_SECOND 100//定义1ms和2s时钟间隔,以ms为单位 ;
- # define TWO_SECOND 2000
- # define TIMER_ACCURACY 1 //定义时钟分辨率,以ms为单位
- UINT wTimerRes_1ms,wTimerRes_2s; //定义时间间隔
- UINT wAccuracy; //定义分辨率
- UINT TimerID_1ms,TimerID_2s; //定义定时器句柄
- void PASCAL OneMilliSecondProc(UINT wTimerID, UINT msg,DWORD dwUser,
- DWORD dwl,DWORD dw2)
- {
- // 定义计数器
- static int ms = 0;
- CCCureView *myview = (CCCureView *)dwUser;
- // 取得系统时间,以ms为单位
- DWORD osBinaryTime = GetTickCount();
- //输出计数器值和当前系统时间
- myview->DrawLine();
- }
- CCCureView::CCCureView()
- {
- // TODO: add construction code here
- // 给时间间隔变量赋值
- wTimerRes_1ms = ONE_MILLI_SECOND;
- wTimerRes_2s = TWO_SECOND;
- TIMECAPS tc;
- //利用函数timeGetDevCaps取出系统分辨率的取值范围,如果无错则继续;
- if(timeGetDevCaps(&tc,sizeof(TIMECAPS))==TIMERR_NOERROR)
- {
- wAccuracy=min(max(tc.wPeriodMin, //分辨率的值不能超出系统的取值范围
- TIMER_ACCURACY),tc.wPeriodMax);
- //调用timeBeginPeriod函数设置定时器的分辨率
- timeBeginPeriod(wAccuracy);
- }
- }
- CCCureView::~CCCureView()
- {
- timeKillEvent(TimerID_1ms); // 删除两个定时器
- timeKillEvent(TimerID_2s); // 删除设置的分辨率
- timeEndPeriod(wAccuracy);
- }
- void CCCureView::InitializeTimer()
- {
- StartOneMilliSecondTimer();
- // StartTwoSecondTimer();
- }
- // 加装1ms定时器
- void CCCureView::StartOneMilliSecondTimer()
- {
- if((TimerID_1ms = timeSetEvent(wTimerRes_1ms, wAccuracy,
- (LPTIMECALLBACK) OneMilliSecondProc, // 回调函数;
- (DWORD)this,// 用户传送到回调函数的数据;
- TIME_PERIODIC)==10))//周期调用定时处理函数;
- {
- AfxMessageBox("不能进行定时!", MB_OK | MB_ICONASTERISK);
- }
- else
- {
-
- } //不等于0表明加装成功,返回此定时器的句柄;
- }
- void CCCureView::OnTime()
- {
- // TODO: Add your command handler code here
- //设置定时器
- InitializeTimer();
- }
- void CCCureView::DrawLine()
- {
- ……
- }
复制代码
下面是提示的错误:(当然去掉上面这些代码,程序是正确的。在VC下这段代码是正确的。
--------------------Configuration: DAQ - Win32 (WCE emulator) Debug--------------------
Linking...
DAQView.obj : error LNK2019: unresolved external symbol __imp__timeBeginPeriod referenced in function "protected: __thiscall CDAQView::CDAQView(void)" (??0CDAQView@@IAE@XZ)
DAQView.obj : error LNK2019: unresolved external symbol __imp__timeGetDevCaps referenced in function "protected: __thiscall CDAQView::CDAQView(void)" (??0CDAQView@@IAE@XZ)
DAQView.obj : error LNK2019: unresolved external symbol __imp__timeEndPeriod referenced in function "public: virtual __thiscall CDAQView::~CDAQView(void)" (??1CDAQView@@UAE@XZ)
DAQView.obj : error LNK2019: unresolved external symbol __imp__timeKillEvent referenced in function "public: virtual __thiscall CDAQView::~CDAQView(void)" (??1CDAQView@@UAE@XZ)
DAQView.obj : error LNK2019: unresolved external symbol __imp__timeSetEvent referenced in function "public: void __thiscall CDAQView::StartOneMilliSecondTimer(void)" (?StartOneMilliSecondTimer@CDAQView@@QAEXXZ)
emulatorDbg/DAQ.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.
DAQ.exe - 6 error(s), 0 warning(s) |
|