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:
我有一个用本机c++编写的应用程序,我想在。net虚拟机上运行它。我在考虑使用Visual Studio 2008编译器重新编译c++ /CLI的c++代码。遗憾的是,我没有找到关于如何做到这一点的任何文件,因此我提出以下问题:
- Does this actually make sense? Am I trying the impossible?
- 这说得通吗?我在尝试不可能的事情吗?
- Where can information on the topic be found?
- 在哪里可以找到有关这个主题的信息?
3 个解决方案
#1
7
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).
许多本机c++代码实际上只是在c++ /CLI上编译和运行。这实际上是一种混合编译器,可以调用本地Win32函数,并使用OpenGL之类的标准C库。您甚至可以直接调用COM接口(使用本机c++编译器可以做的所有事情)。
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库,但是对于这些,您可以创建托管类(使用ref类关键字)。您将使用gcnew为这些类分配内存(来自垃圾收集堆)。使用new和delete(从标准的、非垃圾收集堆中)仍然分配正常类的内存。
In short, you can migrate to .Net in bits and pieces, though there is still some friction when switching between managed and unmanaged classes.
简而言之,您可以零零碎碎地迁移到. net,尽管在托管类和非托管类之间切换时仍然存在一些摩擦。
I found this book useful: Pro Visual C++/CLI.
我发现这本书很有用:Pro Visual c++ /CLI。
#2
#3
2
In C++ you can simply recompile your codebase with /clr. This technique called IJW (It Just Works) so you can easily use your existing classes with CLR.
在c++中,你可以简单地用/clr重新编译你的代码库。这种技术称为IJW(它只是工作),因此您可以轻松地使用CLR的现有类。
#1
7
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).
许多本机c++代码实际上只是在c++ /CLI上编译和运行。这实际上是一种混合编译器,可以调用本地Win32函数,并使用OpenGL之类的标准C库。您甚至可以直接调用COM接口(使用本机c++编译器可以做的所有事情)。
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库,但是对于这些,您可以创建托管类(使用ref类关键字)。您将使用gcnew为这些类分配内存(来自垃圾收集堆)。使用new和delete(从标准的、非垃圾收集堆中)仍然分配正常类的内存。
In short, you can migrate to .Net in bits and pieces, though there is still some friction when switching between managed and unmanaged classes.
简而言之,您可以零零碎碎地迁移到. net,尽管在托管类和非托管类之间切换时仍然存在一些摩擦。
I found this book useful: Pro Visual C++/CLI.
我发现这本书很有用:Pro Visual c++ /CLI。
#2
5
Go to project properties -> General -> Common Language Runtime support -> change to /clr
转到项目属性->通用->通用语言运行时支持->更改为/clr
It's called CLR now. Read about it here and here.
现在它被称为CLR。在这里和这里阅读它。
#3
2
In C++ you can simply recompile your codebase with /clr. This technique called IJW (It Just Works) so you can easily use your existing classes with CLR.
在c++中,你可以简单地用/clr重新编译你的代码库。这种技术称为IJW(它只是工作),因此您可以轻松地使用CLR的现有类。