VC++ Blog Tour Stop: Content Part 5: Roadmap to Using Managed Code
De-myth-ifying Visual C++ .NET, Visual C++ .NET 2003 and Visual C++ 2005
On tour, we constantly battled the following myths and assumptions about our latest releases with regards to managed code:
1. MYTH: Visual Studio .NET 2002 and 2003 only include managed C++ compilers. - False! Non! No! We are proud and excited about the many features and new syntax focused on the .NET Framework - and they come from very same compiler - cl.exe! Existing C++ code remains unchanged and continues without behavioral changes!
2. MYTH: There is nothing new for native C++ developers in any of the releases since Visual Studio 6.0. - False! No! Nein! Njet! If you are reading my blog, you alreay know that there have been many advances for C++ developers all over the map. From libraries to compiler, from conformance to security, from performance to servicing.
3. MYTH: To use the .NET Framework you have to completely rewrite all of your code. - False! Nie! Nu! No! You have options when it comes to leveraging the .NET Framework. You can compile part of your existing project, or all of it, into MSIL, as is! You can just choose to make new code managed, by either compiling it into MSIL or using new syntax.
Why managed code???
Running code on Windows without managed code has limitations:
- Code can only be trusted based on digital signatures and the system can not sandbox privileges for processes
- Libraries targeted at different language developers have to be written several times – once for each language
- Applications written for one platform can not run on other platforms, such as devices, without recompiling
- Data structures can not be easily versioned between DLLs
- APIs have no rich type information for component models
The Common Language Runtime (CLR) provides solutions for these problems. The CLR makes a number of services available to applications:
- Garbage collection and resource management
- Cross-language development
- Security demands for partially trusted code
- Reflection on assembly at run-time
Making use of these CLR services requires additional language enhancements to C++ (enabled by /clr):
- New type categories
- Syntax for garbage collection
- Syntax for properties and events
Of course this is with regards to managed versus managed, since there are some changes encountered on project/version upgrade with regards to conformance, library deprecation and security.
There are lots of great sources for getting familiar with managed code in Visual C++:
C/C++ CLI Migration Primer: http://msdn2.microsoft.com/en-us/library/ms235289(en-US,VS.80).aspx
Webcast on integrating .NET Code into existing C++ code:
http://www.heege.net/webcasts/ExtendingCPlusPlusCodeWithDotNETFeatures/default.html
How To: Compile a project to target the CLR: http://msdn2.microsoft.com/en-us/library/ms235635.aspx
MSDN2 on the syntax for targeting the .NET Framework: http://msdn2.microsoft.com/en-us/library/68td296t(en-US,VS.80).aspx
- april