Writing a DLL in C/C++ for .Net interoperability

后端 未结 4 1276
星月不相逢
星月不相逢 2020-12-04 18:26

In my C# application, I would like to write a part of the code in C. I plan to write a DLL witch would be interoperable with .Net. How can I do that?

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 19:11

    In a nutshell:

    (1) Create a new C++/CLI library project.

    (2) Write your code. For classes that need to be accessible from your C# project, make sure to create them as CLR classes:

    public ref class R {/*...*/};       // CLR class
    public value class V {/*...*/};     // CLR struct
    public interface class I {/*...*/}; // CLR interface
    

    (3) Compile the project and add a reference to it in your C# project.

提交回复
热议问题