一种方法如何编译C库到NET的DLL?方法、NET、DLL

2023-09-03 02:57:30 作者:情多无语

我们可以通过只编译包含code像

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" {
#include <library.h>
}

/ CLR:纯与VS 的说法? (VS10)

with /clr:pure argument with VS? (VS10)

或者我们应该做些更trickey?

Or we should do something more trickey?

推荐答案

我觉得这是最好的使用旧式托管C ++这一点。

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

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);
    }
  };
};

与编译: / CLR:oldSyntax

现在,你可以参考assebmly,并调用 Bar.Foo.foo()从.NET。

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