A way How to Compile C library into .Net dll?

前端 未结 4 1265
别那么骄傲
别那么骄傲 2021-01-05 23:22

Can we compile C library as .Net dll (containing and opening access to all C libs functions) by just compiling cpp project containing code like

extern \"C\"         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 23:48

    I found it is the best to use the old style Managed C++ for this.

    CLR:PURE just wont cut it.

    Example:

    extern "C" int _foo(int bar)
    {
      return bar;
    }
    
    namespace Bar
    {
      public __gc class Foo
      {
      public:
        Foo() {}
    
        static int foo(int bar)
        {
          return _foo(bar);
        }
      };
    };
    

    Compile with: /clr:oldSyntax

    Now you can reference the assebmly, and call Bar.Foo.foo() from .NET.

提交回复
热议问题