Skip to main content
gamedev.net
🔒 Locked

problem with callback functions

Started by browny Nov 14, 2001 at 12:27 AM 1 replies 250+ views
Original Post
browny
browny
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
Z
Muhammad Haggag
Muhammad Haggag
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)



invective
invective
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.