Click to See Complete Forum and Search --> : Callbacks


timber
April 26th, 1999, 10:49 PM
Hi,
I'm porting some VB code to VC++. Need help, hope this is simple.
I have a generic file class in VB. It has a function that takes as one of it
param's a object, specifically a class object...
MyClass
MyCallBackFunc()
...
End Function
Call MyFunc( Me)

MyFileClass
MyFunc(obj as Object)
obj.MyCallBackFunc
End Function

Problem: I can't seem to find the proper way to declare the prototypes or
write the proper code for these functions in VC++. Could someone please
help?

Steve Palmer

Gomez Addams
April 27th, 1999, 04:23 PM
I prefer the typedef approach to this. What I would do is this :

typedef int (*CallBackFunc)( MyFileClass *mfc );

int MyFunc( CallBackFunc func, MyFileClass *mfc )
{
return (*func)( mfc );
}

If you don't need the function as an argument then drop the typedef and use this :

int MyFunc( MyFileClass *mfc )
{
return mfc->MyCallBack();
}

or use a reference :

int MyFunc( MyFileClass & mfc )
{
return mfc.MyCallBack();
}

Hope this helps, just ask if not.