Load Managed C ++ Dlls from Unmanaged C Dll?

I have a finished product that supports custom plugins that need to be written in Unmanaged C. It does not support managed Dll, and my preferred language is C #.

The information that must be returned to the original product is very simple and can be stored in a line.

So, I thought I could do the following:

  • Write the bulk of my code in C # Dll.
  • Write a wrapper in managed C ++ code that calls my C # methods.
  • Write a basic Dll in unmanaged C that invokes a managed C ++ Dll.

Now the connection between managed C ++ and C # Dll is simple.

But I can't figure out how to call a C ++ managed function from an unmanaged c dll. Any help with some simple code example would be great.

thanks

EDIT: I created a Code Project article on how I did this with Alex's answer below. http://www.codeproject.com/Tips/695387/Calling-Csharp-NET-methods-from-unmanaged-code

+4
source share
2 answers

You understand almost everything. Just put the numbers 2 and 3 in the same C ++ / CLI DLL. You can use .NET classes and export C functions from a C ++ / CLI project.

extern "C" __declspec( dllexport ) void __stdcall PureExportC(
                                                    const wchar_t* param
)
{
    CSharpAssemblyNamespace::CSharpWorker worker;
    worker.DoWork( gcnew String(param) );
}
+5
source

I do not think you can do this. But you can write a C ++ (unmanaged) plugin for the product. Then write down the entire managed application using C #, run it from the plugin and communicate between them using named pipes or sockets.

+1
source

All Articles