简体   繁体   English

本机C ++ Exe与C#库进行通信

[英]Native C++ Exe communicating with C# library

I have a following problem: 我有以下问题:

  1. Exe (native C++) implements interfaces Ia and Ib. Exe(本机C ++)实现接口Ia和Ib。
  2. Dll1 (native C++) has a template class D<T> , that implements interface Ic and calls into 3. Exe's Ia's and Ib's implementations. Dll1(本机C ++)具有模板类D<T> ,该类实现接口Ic并调用3。Exe的Ia和Ib的实现。
  3. Dll2 (native C++) implements a class E (class E : public D<E> ) Dll2(本机C ++)实现类E(类E:公共D<E>

At run-time happens following: Exe loads Dll2 (several instances) and instantiates E providing it with pointers to its Ia and Ib pointers. 在运行时发生以下情况:Exe加载Dll2(几个实例)并实例化E,为其提供指向其Ia和Ib指针的指针。 Exe "obtains" Ic pointer from Dll2. Exe从Dll2“获取” Ic指针。

Now, I have to allow implementation of Dll2(s) in C# so that Exe can call into Dll2's Ic impl. 现在,我必须允许在C#中实现Dll2(s),以便Exe可以调用Dll2的Ic impl。 and Dll2 cann call back to Exe's Ia and Ib i-faces. 并且Dll2不能调用Exe的Ia和Ib i面。 Further restriction that I don't have to recompile Exe and Dll1 each time when new Dll2 implementation pops up. 进一步的限制是,当新的Dll2实现弹出时,我不必每次都重新编译Exe和Dll1。

Is it possible to implement something like this ? 是否可以实现这样的事情?

I think you are going to have to move away from inheritance which is already a rather fragile tool when applied across module boundaries. 我认为您将不得不摆脱继承,当跨模块边界应用继承时,继承已经是一个相当脆弱的工具。

I'd point you towards COM. 我会把您指向COM。 Managed code can expose their interfaces as COM objects and C++ can consume them. 托管代码可以将它们的接口公开为COM对象,而C ++可以使用它们。 And vice versa. 反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM