阅读:2118回复:7
CALLBACK在类中被编译为空了吗?
CALLBACK在类中被编译为空了吗?
#include "stdafx.h" class Test { public: Test(); ~Test(); void CALLBACK ResetTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ); }; Test::Test() { } Test::~Test() { } void CALLBACK Test::ResetTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ) { MessageBox(NULL,"1","2",MB_OK); } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. Test t; SetTimer(NULL,0x12345678,1000*60*3,t.ResetTimer); return 0; } 错误信息如下: D:TEMPtt.cpp(16) : error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,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 我是如此定义的 void CALLBACK ResetTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ); 应该就是编译为void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long) 为什么是void (struct HWND__ *,unsigned int,unsigned int,unsigned long)? 因此我认为是CALLBACK被编译为空. |
|
沙发#
发布于:2004-06-15 23:19
直接定义STDCALL即可,何必多此一举???
|
|
|
板凳#
发布于:2004-06-16 09:23
换成__stdcall错误信息一样!
#include "stdafx.h" class Test { public: Test(); ~Test(); void __stdcall ResetTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ); }; Test::Test() { } Test::~Test() { } void __stdcall Test::ResetTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ) { MessageBox(NULL,"1","2",MB_OK); } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. Test t; SetTimer(NULL,0x12345678,1000*60*3,t.ResetTimer); return 0; } |
|
地板#
发布于:2004-06-16 11:45
类的成员函数是thiscall
声明成static的 |
|
地下室#
发布于:2004-06-16 14:39
麻烦!
|
|
5楼#
发布于:2004-06-16 14:40
算了,不放到类中了!
|
|
6楼#
发布于:2004-06-18 16:04
你做什么东西,要用回掉
WINDOWS的消息处理机制用类封装? 但好像也不是这样封装 |
|
|
7楼#
发布于:2004-07-16 08:32
你声明的时候是一个全局函数,但是定义的时候变成了类内函数,这当然会产生编译错误。
|
|