Jump to content



WndClassEx.lpfnWndProc = Member Function?

  • You cannot reply to this topic
2 replies to this topic

#1 Jemburula   Members   -  Reputation: 340

Like
0Likes
Like

Posted 13 April 2006 - 10:40 PM

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

Ad:

#2 superpig   Staff Emeritus   -  Reputation: 1801

Like
0Likes
Like

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.

#3 Jemburula   Members   -  Reputation: 340

Like
0Likes
Like

Posted 13 April 2006 - 11:15 PM

Oh good god. Looks like I'll have to bust open a bottle of red to nut this one out overnight. Looks complex Hmm. Anyway! Thankyou yet again SuperPig, you are a legend.






We are working on generating results for this topic
PARTNERS