Hey,
I've been trying to use a member function as the callback for WndClassEx.lpfnWndProc but I just can't figure out how. I currently have tried WndClassEx.lpfnWndProc = &this->WndProc (this is in the Initialize member function of my class) then that didn't work so I tried something and got completely lost.
LRESULT CALLBACK (*WinProcPointer)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) = &this->WinProc;
Pretty much the same thing I suppose so it doesn't work either. Hmm, so I'm not really sure what to do! Must it be a static member function or something? Thanks for your help, much appreciated!
Jemburula
WndClassEx.lpfnWndProc = Member Function?
Started by Jemburula, Apr 13 2006 10:40 PM
2 replies to this topic
Ad:
#2 Staff Emeritus - Reputation: 1801
Posted 13 April 2006 - 10:46 PM
The problem is that non-static member functions have a hidden extra bit of data that gets passed to them - the 'this' pointer. As such a function that /appears/ to be (HWND, UINT, WPARAM, LPARAM) is actually (MyObject*, HWND, UINT, WPARAM, LPARAM) - or, as the compiler will report, MyObject::(HWND, UINT, WPARAM, LPARAM).
The way to resolve this is, as you say, to make the member function static - that way, the function no longer takes the 'this' pointer and the types will match up.
However, when you do that you'll no longer have access to your object data (because your function is static and cannot use the 'this' pointer). The way to get around this is most commonly to use the window's private data - like this.
The way to resolve this is, as you say, to make the member function static - that way, the function no longer takes the 'this' pointer and the types will match up.
However, when you do that you'll no longer have access to your object data (because your function is static and cannot use the 'this' pointer). The way to get around this is most commonly to use the window's private data - like this.


















