0

What is the best solution to access c# code via native code (C++)?

I have C# code which I want to call from native project, so I'm considering writing a COM wrapper but I wonder whether there is a better option (framework/design pattern/architecture etc.) available in .NET?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
BreakPoint
  • 93
  • 1
  • 12

1 Answers1

1

COM interop is without a doubt the best bet. It's a known, supported framework for achieving exactly what you want to achieve.

There is another alternative however - it is possible to edit the IL code inside a compiled .NET assembly to flag methods within the assembly as native exports. A detailed breakdown of the changes can be found in this CodeProject article.

Robert Giesecke has created Unmanaged Exports to simplify this process using simple method attributes. A NuGet package can be found here.

pixelbadger
  • 1,556
  • 9
  • 24