Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Vangelis

Function pointers as members of class

This topic is 5453 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 a class with a function that I'm hoping to use as a dialog callback procedure. But when I try to create a dialog using that function, I get errors like...
error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'int (struct HWND__ *,unsigned int,unsigned int,long)'
 to 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'  
The prototype for the function is
BOOL CALLBACK EditDlgProc(HWND,UINT,WPARAM,LPARAM);  
and I'm attempting to create the dialog (in another member function) by
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_EDITDLG),mainWindow,EditDlgProc);  
I'm guessing it has to do with how member functions are treated differently that non-member functions and this all involves stdcall. Is there a standard way of getting around this? [edited by - Vangelis on August 12, 2003 11:37:39 PM]

Share this post


Link to post
Share on other sites
Advertisement
Make the function static, then find a way to pass instance-specific information to it (for example, create a mapping from HWND -> dialog class instance).

Share this post


Link to post
Share on other sites
The dreaded pointer to member function question:

http://www.parashift.com/c++-faq-lite/pointers-to-members.html

basically non static member fucntions have an implicit this parameter, so no matter what you do, the function parameter list is not going to match. You have to use a static function.

Share this post


Link to post
Share on other sites
Why not just pass the dialog, a pointer or reference to the instance you wish to perfrom the call back on?

this is probably pretty safe if the dialog is modal.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!