How to dynamically load a C# dll from a C++ DLL

限于喜欢 提交于 2019-12-03 13:43:47
Padu Merloti

Another way of doing this would be creating a C++/CLI project that hosts your C# classes and use it as a bridge in your C++ project.

A few more links to this approach:

The latest link has simple source code for the bridge

aL3891

What you'd do is basically start up an instance of the CLR in your process. Have a look at this article on CLR hosting

Here are some slides that describe my solution.

https://docs.google.com/presentation/pub?id=1YoJRGnveh4By7ym4GL19L7OzYOFORZQB6RgJEPVfFb8&start=false&loop=false&delayms=3000

My solution was to have a win32 plugin dll, loaded through normal means (LoadLibrary) that links to mixed C++/CLI dll, which links to pure managed C# code. I allowed calls to happen both ways using A LOT of boiler plate, and a double c++/cli bridge pattern based off of the link given by Padu. Details were fairly complex, but the job of the end API user is very easy and that was my goal. The managed plugin object writer simply derives from an object, and everything just works.

Essentially I made a pattern that provides "mixed mode pseudo inheritance" Now my c# objects derive from a base class in c++.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!