需要为C ++ / CLI创建哪种类型的项目? [英] What type of project needs to be created for C++/CLI?

查看:89
本文介绍了需要为C ++ / CLI创建哪种类型的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为C ++ / CLI中的本机C ++方法编写包装,这将使它们暴露给C#。现在,我正在使用Visual Studio2008。有人可以告诉我需要创建哪种类型的项目,以便我的包装程序可以使用C#。我在Visual Studio 2008中看到在Visual C ++ ---> CLR ---->

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

我应该使用哪个?

推荐答案

您必须创建类库类型的项目。最重要的是在项目属性->配置属性->常规

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

这将允许您使用

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

编译指示并链接到本地​​.lib文件。

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

有一个问题(在此未提及)文章)用于64位版本。对于64位,链接程序->输入->强制符号引用必须设置为 _ DllMainCRTStartup,对于32位,必须将其设置为 _DllMainCRTStartup @ 12。

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.

这篇关于需要为C ++ / CLI创建哪种类型的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆