需要为C ++ / CLI创建什么类型的项目?

我正在为C ++ / CLI中的本机C ++方法编写一个包装器,它将它们暴露给C#。 现在我正在使用Visual Studio 2008.任何人都可以告诉我需要创建什么类型的项目,以便我的包装器将暴露给C#。 我在Visual Studio 2008中看到Visual C ++ —> CLR —->下有不同类型的项目

class library, CLR Empty Project, Windows form control library, CLR Console Application, Windows Forms Application, Windows Service 

我应该使用哪一个?

您必须创建类库类型的项目。 最重要的是在项目属性 – >配置属性 – >常规中指定“公共语言运行时支持”选项(设置为“公共语言运行时支持(/ clr)”)

这将允许您使用

 #pragma managed ... use your native stuff here #pragma unmanaged 

编译指示和本机.lib文件的链接。

有关细微信息,请参阅此链接

http://www.codeguru.com/cpp/cpp/cpp_managed/interop/article.php/c6867/Consuming-Unmanaged-C-Class-Libraries-from-NET-Clients.htm

64位版本中有一个catch(本文未提及)。 对于64位, “Linker-> Input-> Force Symbol References”必须设置为“_ DllMainCRTStartup”,对于32位,必须设置为“ _DllMainCRTStartup @ 12”。