Archived

This topic is now archived and is closed to further replies.

CALLBACK Func in class?

This topic is 5743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to place the windows callback function in a class. But when I do I get these errors c:\windows\desktop\directx\wrappers\mainobject.cpp(56) : error C2440: ''='' : cannot convert from ''long (__stdcall CMainObject::*)(struct HWND__ *,unsigned int,unsigned int,long)'' to ''long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'' There is no context in which this conversion is possible c:\windows\desktop\directx\wrappers\mainobject.cpp(98) : error C2589: ''__stdcall'' : illegal token on right side of ''::'' c:\windows\desktop\directx\wrappers\mainobject.cpp(98) : warning C4091: '''' : ignored on left of ''long'' when no variable is declared c:\windows\desktop\directx\wrappers\mainobject.cpp(98) : error C2143: syntax error : missing '';'' before ''::'' c:\windows\desktop\directx\wrappers\mainobject.cpp(98) : error C2143: syntax error : missing '';'' before ''::'' c:\windows\desktop\directx\wrappers\mainobject.cpp(99) : error C2143: syntax error : missing '';'' before ''{'' c:\windows\desktop\directx\wrappers\mainobject.cpp(99) : error C2447: missing function header (old-style formal list?) Error executing cl.exe. Wrappers.exe - 6 error(s), 1 warning(s) Here is the definition. //window callback LRESULT CMainObject::CALLBACK WinFunc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); return 0; break; case WM_KEYDOWN: PostQuitMessage(0); return 0; break; default: return DefWindowProc(hwnd, msg, wparam, lparam); } return 0; } Why doesn''t this work? DDraw. She has double D''''s

Share this post


Link to post
Share on other sites
If it''s a callback you have to make it a static member function.

Of course this means the function doesn''t have a "this" pointer (and doesn''t know what class it belongs to), so you''ll need to pass that in through SetWindowLong or some other method.

- Pete


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
Ok I made it a static and it worked. But I the window doesn''t get any messages. It just sits there. This is my code for processing a message.
while(true)
{
if(PeekMessage(&main.objGetMessage(), NULL, 0,0, PM_REMOVE))
{
if(main.objGetMessage().message == WM_QUIT)
break;
TranslateMessage(&main.objGetMessage());
DispatchMessage(&main.objGetMessage());
}
//do game stuff here
}



in class
MSG CMainObject::objGetMessage()
{
return m_msg;
}

in class as private
MSG m_msg;


Why doesn''t the window get the messages?

DDraw. She has double D''''s

Share this post


Link to post
Share on other sites