Frerich Raabe
Frerich Raabe

Reputation: 94529

(How) can I export a function from a .NET assembly without using C++/CLI?

I'm working on a C# component which consists of two DLLs:

  1. A .DLL written in C++/CLI exporting a symbol; unfortunately, this DLL dynamically links against the CRT and there doesn't seem to be a way around that.
  2. A C# assembly.

The C++/CLI DLL gets loaded and then loads the C# assembly (and forwards most calls to it). Is it possibly to simplify this scenario so that I export a symbol from the C# assembly right away?

Upvotes: 0

Views: 1789

Answers (2)

Frerich Raabe
Frerich Raabe

Reputation: 94529

I ended up going for the solution described in http://www.codeproject.com/Articles/37675/Simple-Method-of-DLL-Export-without-C-CLI

The general approach is to have a dedicated attribute which is used to decorate the functions to be exported. After building the assembly, ildasm is used to disassemble it. The resulting IL is patch a little bit so that the previsouly decorated functions are exported, then the IL is assembled into an assembly again.

Upvotes: 0

nvoigt
nvoigt

Reputation: 77364

You can export your functionallity from C# as a COM server this way it should be pretty easy to call it from C++ as you would do with any other non-C# COM object.

Upvotes: 1

Related Questions