简体   繁体   中英

Native C++ Exe communicating with C# library

I have a following problem:

  1. Exe (native C++) implements interfaces Ia and 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.
  3. Dll2 (native C++) implements a class E (class E : public 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 "obtains" Ic pointer from Dll2.

Now, I have to allow implementation of Dll2(s) in C# so that Exe can call into Dll2's Ic impl. and Dll2 cann call back to Exe's Ia and Ib i-faces. Further restriction that I don't have to recompile Exe and Dll1 each time when new Dll2 implementation pops up.

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. Managed code can expose their interfaces as COM objects and C++ can consume them. And vice versa.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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