What type of project needs to be created for C++/CLI?

一曲冷凌霜 提交于 2019-12-30 06:42:06

问题


I am writing a wrapper for my native C++ methods in C++/CLI which will expose them to C#. Now I am using Visual Studio 2008. Can any one tell me what type of project I need to create so that my wrapper will be exposed to C#. I see in Visual Studio 2008 there are different types of projects under Visual C++--->CLR---->

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

Which one should I use?


回答1:


You have to create the project of type Class Library. The most important thing is to specify the "Common Language Runtime Support" option (set to "Common Language Runtime Support (/clr)") in the Project Properties -> Configuration Properties -> General

This will allow you to use the

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

pragmas and link with the native .lib files.

See this link for subtle details

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

There is a catch (not mentioned in this article) for 64-bit builds. The "Linker->Input->Force Symbol References" must be set to "_DllMainCRTStartup" for 64-bit and to "_DllMainCRTStartup@12" for 32-bit.



来源:https://stackoverflow.com/questions/10642375/what-type-of-project-needs-to-be-created-for-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!