一种如何将C库编译成.Net dll的方法?

Rel*_*lla 5 .net c c++ clr visual-studio

我们可以通过编译包含代码的cpp项目来编译C库作为.Net dll(包含并打开对所有C库函数的访问)

extern "C" {
#include <library.h>
}
Run Code Online (Sandbox Code Playgroud)

/clr:pure在VS的说法?(VS10)

或者我们应该做更多的东西?

lep*_*pie 3

我发现最好使用旧式托管 C++。

CLR:PURE只是不会削减它。

例子:

extern "C" int _foo(int bar)
{
  return bar;
}

namespace Bar
{
  public __gc class Foo
  {
  public:
    Foo() {}

    static int foo(int bar)
    {
      return _foo(bar);
    }
  };
};
Run Code Online (Sandbox Code Playgroud)

编译:/clr:oldSyntax

现在您可以引用该程序集,并Bar.Foo.foo()从 .NET 进行调用。