Load Managed C++ Dll from Unmanaged C Dll?

Viewed 1464

I have an off the shelf product which supports custom plugins which need to be written in Unmanaged C. It doesn't support Managed Dll's and my language of preference is c#.

The information which needs to be passed back to the off the shelf product is very basic and can be held in a string.

So I was thinking I could do the following:

  1. Write the bulk of my code in a C# Dll.
  2. Write a wrapper in C++ Managed Code which calls my C# Methods.
  3. Write a basic Dll in unmanaged C which calls the Managed C++ Dll.

Now communicating between a Managed C++ and C# Dll is easy.

But I cant figure out how to call a managed c++ function from an unmanaged c dll. Any help with some simple sample code 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

2 Answers
Related