Using C# dll in C++ code

42,879

There are basically two cases to call a .NET DLL from unmanaged code:

  1. The .NET DLL exposes a COM interface. In this case, you can use COM from your C++ code.
  2. The .NET DLL does not expose a COM interface. In this case, you have two possibilities (to make it simple):

    2.a. host the CLR as described here: Loading the Common Language Runtime into a Process
    2.b. write a piece of managed C++ code (another DLL - written in C++/CLI) to wrap the .NET DLL and expose 'old way' DLL exports to unmanaged clients.

I don't specifically know the sharpbox system, but it looks like it's pure .NET and does not expose COM interfaces, so 2.b might be the best way to do it (not so easy...). Maybe it has a REST/Web easier API you could use.

PS: you can also add exports to a .NET DLL. This is described here: Is is possible to export functions from a C# DLL like in VS C++? but it's kinda hacky.

Share:
42,879
Sunrise
Author by

Sunrise

Updated on October 03, 2020

Comments

  • Sunrise
    Sunrise over 3 years

    I need to integrate this C# dll in my C++ code. I want to call some functions written in C# from dll and the rest of code write in C++. What is the easiest and quickest way to do it? The program will be executed only on Windows.