I have unmanaged C++ DLL (MFC Extension DLL to be precise). This DLL loads the C# DLL and calls its method Start() as shown below. All this works.
C++ ==============================================
BOOL CForwarder::Start()
{
return InitMyManagedFlex();
}
// CForwarder member functions
BOOL CForwarder::InitMyManagedFlex()
{
// Initialize COM.
HRESULT hr = CoInitialize(NULL);
// Create the interface pointer.
IForwarderPtr pIFwd(__uuidof(MyForwarder));
long lResult = 0;
VARIANT_BOOL ret = FALSE;
BSTR bstr = AsciiToBSTR("AAA");
// Call the Add method.
pIFwd->Start(bstr, &ret);
SysFreeString(bstr);
wprintf(L"The result is %d\n", ret);
// Uninitialize COM.
CoUninitialize();
return (ret == VARIANT_TRUE) ? TRUE : FALSE;
}
// Interface declaration.
public interface IForwarder
{
bool StartCmd(string msg);
};
==================================================================
The C# class in C# DLL looks like this:
namespace MyManagedFlex
{
public class MyForwarder:IForwarder
{
public bool StartCmd(string msg)
{
return StartSending();
}
private bool StartSending()
{
return true;
}
}
// Interface declaration.
public interface IForwarder
{
bool StartCmd(string msg);
};
}
Here is the basic question: How do I pass a callback function in Start() and how and what I implement in C++ and C# so that C# could call back C++ DLL at any time it desires and pass some parameters.