如何在C ++ / CLI中编写第三方本机C ++方法回调

时间:2019-05-30 06:22:08

标签: c++-cli

我有一个本地C ++库,Application Client可以在其​​中注册回调方法。 我在C ++ / CLI中为本机C ++库编写Wrapper(DLL)。 就像我们在nativeAppClient类中使用的那样,此Wrapper Dll将在C#应用程序中使用。 需要帮助以了解如何像在CPP NativeApplication中一样获得C#应用程序中的回调

P.S:-为简单起见,我有意删除了代码并仅突出显示了我需要帮助的部分。 此类库类的用法如下,在C ++应用程序中(即nativeAppClient类)

//In nativeAppClient.h .. Native Cpp client using consumerClient from C++ library
// application defined client class for receiving and processing of  messages
public class nativeAppClient : public ConsumerClient
{
protected:
    void onReciveMsg(const ConsumerMsg&, const ConsumerEvent&);
};

// ConsmerClient.h -- Third party class 
// consumerClient has onReciveMsg method , which we overrides in nativeAppClient to process async callback
class ConsumerClient
{
public:
    virtual  void onReciveMsg(const ConsumerMsg&, const ConsumerEvent&);
}

// In nativeAppClient.cpp 
void nativeAppClient::onReciveMsg(const ConsumerMsg& refreshMsg, const ConsumerEvent&)
{
    // Do some processing on received message on async callback 
}

int main()
{
    nativeAppClient ObjnativeAppClient;
    consumer ObjConsumer(/* Add consumer details */); // Another class to specify config details & call register method to register nativeclient 
    ObjConsumer.register(/* Request details */, ObjnativeAppClient); // here we pass the object of NativeAppClient which was inherited from ConsumerClient Class  
}

0 个答案:

没有答案