-
Callbacks
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
-
Re: Callbacks
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.