How to port C ++ code to C ++ / CLI in Visual Studio?

I have an application written in native C ++ that I would like to run on a .NET virtual machine. I was thinking of recompiling C ++ code as C ++ / CLI using the Visual Studio 2008 compiler. Unfortunately, I cannot find documentation on how to do this, so therefore my questions are:

  • Does that really make sense? Am I trying to do the impossible?
  • Where can I find information on this topic?
+6
c ++ visual-studio c ++ - cli
source share
3 answers

A lot of native C ++ codes are actually just compiled and run in C ++ / CLI. It really is a kind of hybrid compiler that can call Win32 native functions and use standard C libraries such as OpenGL. You can even directly invoke COM interfaces (anything you can do with your own C ++ compiler).

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

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

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

+7
source share

Go to project properties -> General -> Common Language Runtime runtime support -> change to / clr

Now it is called CLR. Read about it here and here .

+5
source share

In C ++, you can simply recompile your code base with / clr. This method is called IJW (It Just Works), so you can easily use existing classes with the CLR.

+2
source share

All Articles