C++ and WIN32 API's WNDPROC

Started by
6 comments, last by leandro 19 years, 11 months ago
I''m trying to make a class that contains a callback message handler function as a member. The problem is I cann''t convert it to a WNDPROC to use it as a Window''s callback function. I mean: class myclass { public: LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); } void myfunction(WNDPROC MsgHandler) {} void winmain(...) { myclass myobject; myfunction(myobject.MsgHandler); //<-- Error!!!; //or myfunction((WNDPROC)myobject.MsgHandler); // Error !!! }
Advertisement
This might be completely wrong since I might have missunderstod your problem. But anyway, declaring your MsgHandler function as static should solve the problem.

class myclass {
public:
static LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg,
WPARAM wparam, LPARAM lparam);
}

LRESULT CALLBACK myclass::MsgHandler( HWND hw... )
{

}

The Lord says He can get me out of this mess, but He''s pretty sure you''re fucked.
- Stephen (Braveheart)
Making your WNDPROC static should solve the problem. Remember to use
myfunction(myobject::MsgHandler);
instead, since it''s static.
2 + 2 = 5 for extremely large values of 2
The answer is correct but the problem is that inside the
class myclass there are non static objects that get called from
whithin the MsgHandler. I could do those objects static too, but I want to know if there is another solution.
I''m reasonably sure you simply can''t have your WNDPROC be a non-static member function.
President: Video Game Development Club of UCIhttp://spirit.dos.uci.edu/vgdc
One solution: use a static WndProc that get's the actual pointer to the window object (either using a map or storing the pointer in the window data). then you can call the non static method. But you should use the forum's search function, this question has been asked several times.

[edited by - VolkerG on May 22, 2004 3:15:07 AM]
Thanks to everyone. I guess I''ll have to change plans.
Read.

This topic is closed to new replies.

Advertisement