
How to handle VB AddressOf in VC?
Quote:
> I understand we can use AddressOf in VB5 or greater to send Callback
> function. I just work like to know how to write a VC function to handle
the
> VB AddressOf pointer. Could anyone help?
> For example:
> VB6
> Call VCCallBack(AddressOf MyFunction)
> ...
> Public Function MyFunction
> ...
> End Function
> VC6
> How to write the code to receive the procedure pointer to MyFunction and
> call it from VC?
> Any idea? TIA.
There are at least two ways you can do this.
This first way may also be compatible with C:
void FunctionX(int(*A)(int A, int B))
{
// Use the function
int X = (*A)(12,1);
Quote:
}
int MyCallbackFunction(int A, int B);
// To actually send the function
FunctionX(MyCallbackFunction);
The second way uses the OOP aspect of C++
class CallbackBase_FunctionX
{
public:
virtual int Call(int A, int B) = 0; // Make this class "purely abstract"
Quote:
};
class MyCallbackFunction: public CallbackBase_FunctionX
{
public:
virtual int Call(int A, int B)
{
// Code
};
Quote:
};
I haven't tried compiling the code so this may be subject to a little syntax
correction, but it should demonstrate the idea well enough.
Also, this should work on any compiler.
Hope this helped
CJ