我正在编写一个C#应用程序以使用C ++代码。我已经为此写了一个C ++ / CLI包装器。现在,我可以调用函数并获取Integer,String和其他对象类型的返回值。但是,我被困了两个星期才能实现一个函数,该函数将返回和/或采用shared_ptr类型的参数。请帮助我,这是我第一次写包装纸。谢谢。
C ++函数:
SDKManager(std::shared_ptr<CoreListener> corelistener, std::shared_ptr<CscReceiver> csclistener);
void CreateSDK(std::shared_ptr<CoreListener> corelistener, std::shared_ptr<CscReceiver> csclistener, void* userdata);
std::shared_ptr<CoreListener> MakeCall(std::wstring number, CALL_TYPE type, bool isVideo);
C ++ / CLI:
public ref class SDKManagerWrapperClass {
SDKManager *_pSDKManager;
public:
SDKManagerWrapperClass(<params of handler type>) {
//Conversion to be made from handler to shared_ptr type
//to call the C++ function
_pSDKManager = new SDKManager(<params of shared_ptr type>);
}
void CreateSDKWrapper(<params of handler type>) {
//Conversion to be made from handler to shared_ptr type, and void*
//to call the C++ function
_pSDKManager->CreateSDK(<params of shared_ptr type>);
}
<handler type> MakeCallWrapper(<params of handler type>) {
//Conversion from handler type
return _pSDKManager->MakeCall(<params>);
}
}
C#应用程序:
CoreListener m_coreListener = new CoreListenerWrapper(); //works fine
CscReceiver m_CscReceiver = new CscReceiverWrapper(); //works fine
//Doesn't work. Error: Not supported by the language
IPGSDKManagerWrapperClass m_SDKmanager = new IPGSDKManagerWrapperClass(m_coreListener, m_CscReceiver);
m_SDKmanager.CreateSDKWrapper(<params of handler type>);
handler = m_SDKmanager.MakeCallWrapper(<params of handler type>);
现在,如何在C ++ / CLI中正确编写构造函数和两个函数,以便可以正确地调用它们并在C#应用程序中接收它们返回的值?还有如何从C#应用程序正确调用它们。