How to dynamically load c # dll from c ++ dll

I have a C ++ application. This supports C ++ user plugin DLL files, they will dynamically load these DLLs, and then they will be able to dynamically create and use user types. These user types are based on the basic types and interfaces defined in the main library of the main applications, so I keep the user objects as pointers to the base class and call the user virtual functions to make them magic.

Now I want to extend the plugin DLL to allow a managed DLL (I mainly care about C #). I want all sorts of magic to happen in C # DLL plugins.

How can I dynamically load these dlls, some, as I think, win32 LoadLibrary, which I am currently using, will be pleased with the managed DLL. I will not have access to these libraries at the time of compilation / link, they come from the user.

After loading the library, unfortunately, I suspect that in the future I will use COM to call derived functions. Perhaps I could use the CLI / C ++ wrapper that I read about, but I'm very inexperienced here and would be grateful for any advice or links to related articles.

+7
source share
3 answers

Another way to do this would be to create a C ++ / CLI project that will host your C # classes and use it as a bridge in your C ++ project.

A few more links to this approach:

The last link has simple source code for the bridge

+2
source

What would you do is basically launch a CLR instance in your process. Check out this article on CLR hosting

+2
source

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 dll plugin loaded by conventional means (LoadLibrary) that references a mixed C ++ / CLI library that references pure C # managed code. I allowed to call in both directions using the LOT of the boiler plate, and a double C ++ / cli template based on the link provided by Pad. The details were pretty complex, but the end-user API work is very simple, and that was my goal. The managed object-object-plugin just comes from the object, and everything just works.

Essentially, I created a template that provides "mixed mode pseudo-inheritance." Now my C # objects come from a base class in C ++.

0
source

All Articles