SetTimer 问题

时间:2015-01-30 09:19:50   收藏:0   阅读:175



在控制台下,以如下方式定义一个定时器:

UINT_PTR TimerID = SetTimer(NULL,1,1000,MyTimerProc);

其回调函数如下定义:
VOID CALLBACK TimerProc(
  HWND hwnd,         // handle to window 
  UINT uMsg,         // WM_TIMER message  
  UINT_PTR idEvent,  // timer identifier  
  DWORD dwTime       // current system time
  );
按以上定义方式,程序会报以下错误:
error C2664: ‘SetTimer‘ : cannot convert parameter 4 from ‘void (struct HWND__ *,unsigned int,unsigned long,unsigned long)‘ to ‘void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)‘       None of the functions with this name in scope match the target type
错误类型为:回调函数类型不一致。
解决方法为:将MyTimerProc回调函数进行强转。
UINT_PTR TimerID = SetTimer(NULL,1,1000,(TIMERPROC)MyTimerProc);

注:以上错误只在vs6.0中出现,在更高版本的vs中无需对回调函数进行强转。

本文出自 “whatever957” 博客,请务必保留此出处http://whatever957.blog.51cto.com/6835003/1609843

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!