Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting functions from a C# class library

Tags:

c++

c#

export

dll

How would I export functions defined in a C# class library, while enabling them to be imported to and called from an unmanaged C++ application/DLL ?

like image 975
shadeMe Avatar asked Dec 18 '22 02:12

shadeMe


2 Answers

Strictly speaking, you can't just export functions as you would in a classic .dll, as .NET .dll's aren't really .dll's at all. Your only three options are:

  1. Use managed C++
  2. Expose your C# classes as COM objects and consume them from your C++ code
  3. Host the .NET runtime in your C++ project and interact with your C# classes through that.
like image 120
Adam Robinson Avatar answered Dec 24 '22 01:12

Adam Robinson


Your C++ Apllication would have to start by hosting the CLR. There is nothing special required from the .NET DLL.

like image 31
Henk Holterman Avatar answered Dec 24 '22 01:12

Henk Holterman