Jump to content
  • Advertisement
Sign in to follow this  
Eldritch

WINAPI: Event handler as part of a class?

This topic is 4654 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 have attempted to put my application window's event handler in a class. This generated a peculiar error during compilation. Here's what I have done: In my class, Engine, I have the following function as a public member: LRESULT CALLBACK EventHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); When I create my window (in another public member function of the Engine class called createWindow()), I do the following declaration:
wc.lpfnWndProc = EventHandler; // Event handler.



wc is a WNDCLASS variable. I get the following error during compilation: error C2440: '=' : cannot convert from 'long (__stdcall Engine::*)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned

Share this post


Link to post
Share on other sites
Advertisement
The key here is indeed a part of the error message, although it might not be obvious at first glance: "(__stdcall Engine::*)" as compared to "(__stdcall *)". Since EventHandler is a non-static member of a class, there is an implicit/hidden variable that the function receives in a normal call, which is a reference/pointer to an instance of the class it belongs to. The lpfnWndProc variable needs a standard __stdcall* that isn't tied to an object. Your options are to make it a global function, to make it a static member function, or to use a wrapper such as those provided by the boost library.

Hope that helps,
Twilight Dragon

Share this post


Link to post
Share on other sites
check out the OOP version of Nehe's base code, it's a little hard to follow, but it does exactly what you're trying to do.
nehe.gamedev.net

Share this post


Link to post
Share on other sites
Aha, could not have figured that one out, thanks.

I checked the OOP code.. was not structured as a class it seemed.. I dunno Delphi though :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!