我有非托管C ++ DLL(确切地说是MFC扩展DLL)。 此DLL加载C#DLL并调用其方法Start(),如下所示。 这一切都有效。
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);
};
=============================================== ===================
C#DLL中的C#类如下所示:
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);
};
}
这是一个基本问题:如何在Start()中传递回调函数以及我在C ++和C#中实现的方式和内容,以便C#可以随时回调C ++ DLL并传递一些参数。