如何在Visual Studio中将C ++代码移植到C ++ / CLI? [英] How to port C++ code to C++/CLI in Visual Studio?

查看:132
本文介绍了如何在Visual Studio中将C ++代码移植到C ++ / CLI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序用本机C ++编写,我想在.NET虚拟机上运行。我想用C ++ / CLI重新编译C ++代码,使用Visual Studio 2008编译器。遗憾的是,我没有找到任何有关如何做到这一点的文档,因此我的问题:

I have an application written in native C++ which I'd like to get running on the .NET virtual machine. I was thinking of recompiling the C++ code as C++/CLI, using the Visual Studio 2008 compiler. Regrettably, I don't find any documentation on how to do this, so hence my questions:


  • 这真的有意义吗?


  • Does this actually make sense? Am I trying the impossible?
  • Where can information on the topic be found?

推荐答案

很多本地C ++代码实际上只是在C ++ / CLI上编译和运行。这实际上是一种可以调用本地Win32函数并使用标准C库(如OpenGL)的混合编译器。你甚至可以直接调用COM接口(所有的东西,你可以做一个本地的C + +编译器)。

A lot of native C++ code will actually just compile and run on C++/CLI. This is really a kind of hybrid compiler that can call native Win32 functions and use standard C libraries like OpenGL. You can even call COM interfaces directly (all the stuff you can do with a native C++ compiler).

也可以使用.Net库,但是这些库可以创建托管类(使用 ref class 关键字)。您将使用 gcnew 为这些类(来自垃圾收集的堆)分配内存。仍然使用删除(从标准的非垃圾回收堆)分配普通类的内存。

The .Net library is also available but for these you create managed classes (using the ref class keyword). You will use gcnew to allocate memory for these classes (from a garbage collected heap). Memory for your normal classes is still allocated using new and delete (from a standard, non garbage-collected heap).

总之,你可以迁移到.Net的位和块,虽然在托管和非托管类之间切换时仍有一些摩擦。

In short, you can migrate to .Net in bits and pieces, though there is still some friction when switching between managed and unmanaged classes.

我认为这本书很实用: Pro Visual C ++ / CLI < a>。

I found this book useful: Pro Visual C++/CLI.

这篇关于如何在Visual Studio中将C ++代码移植到C ++ / CLI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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