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 ?
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:
- Use managed C++
- Expose your C# classes as COM objects and consume them from your C++ code
- Host the .NET runtime in your C++ project and interact with your C# classes through that.
You would not. Not supported. You can pretty much only export COM objects from a C# class librarly.
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).