Jump to content
  • Advertisement
Sign in to follow this  
Jemburula

WndClassEx.lpfnWndProc = Member Function?

This topic is 4882 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

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!