开发者

Exporting functions from a C# class library

How would I export functions defined in a C# class library, while enab开发者_开发问答ling 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:

  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.


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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜