Archived

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

browny

problem with callback functions

Recommended Posts

Everything wos goin along fine with MFC''s object oriented programming until now when i''m getting this real annoying error message everytime i''m compiling the following source code: the error message is: ERROR: cannot convert long(struct _DDSURFACEDESC * ,void *) to long (__stdcall*) (struct _DDSURFACEDESC *,void *) the source code is: // callback function HRESULT WINAPI CSettingDlg::DisplayModes(LPDDSURFACEDESC pddsd,LPVOID lpContext) { //blah blah } HRESULT CSettingDlg::LoadDisplayModes(LPDIRECTDRAW lpDD) { // this is where the error message is poping up HRESULT hr = lpDD->EnumDisplayModes(DDEDM_STANDARDVGAMODES,NULL,NULL,DisplayModes); } Interestingly when i write the same codes in procedural method ( normal C-style procedural function) it WORKS !!!!!!!!!!!!!!!!!! Now, what''s goin on ??????? Please help

Share this post


Link to post
Share on other sites
I believe that :

quote:
HRESULT hr = lpDD->EnumDisplayModes(DDEDM_STANDARDVGAMODES,NULL,NULL,DisplayModes);

DisplayModes is seen by the compiler as :
HRESULT DisplayModes(CSettingDlg* this,LPDDSURFACEDESC pddsd,LPVOID lpContext)
while EnumDisplayModes expects a pointer to a function without the this pointer. Something like :
HRESULT DisplayModes(LPDDSURFACEDESC pddsd,LPVOID lpContext)


Share this post


Link to post
Share on other sites
Yes, the problem is that the function is associated with the class and has an implict this parameter. You have to fudge the callback by making it static or passing it a global pointer. You can read about pointers to member functions here:
http://www.parashift.com/c++-faq-lite/pointers-to-members.html

Share this post


Link to post
Share on other sites