Reputation: 716
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 ?
Upvotes: 4
Views: 4765
Reputation: 10349
You could also make a C++ wrapper for your C# library - a simple Managed C++ DLL that would import .NET methods and export them natively. This adds an additional layer, but it might be useful if C# library is a must have.
Another option is to tweak the compiled assembly to export the functions. A C# compiler cannot do this, but it takes a slight change of MSIL code to get the things done. Have a look at this article - there're some links on how the stuff works, and a tool to automate it (though I haven't tried it myself).
Upvotes: 1
Reputation: 273169
Your C++ Apllication would have to start by hosting the CLR. There is nothing special required from the .NET DLL.
Upvotes: 2
Reputation: 62093
You would not. Not supported. You can pretty much only export COM objects from a C# class librarly.
Upvotes: 1
Reputation: 185593
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:
Upvotes: 8