To enable Visual C++ developers to write applications for the .NET Framework, Microsoft has introduced Managed Extensions for C++. Managed Extensions for C++ provide support for managed programming. Managed programming comprises code that supports automatic garbage collection.
Managed extensions provide the following benefits:
If you have an existing unmanaged C++ application, Managed Extensions provide a smooth transition to the .NET Framework. Because you can mix unmanaged and managed code in the same application, you can move code over time, component by component, to the .NET Framework. Or you can continue to write components in unmanaged C++, taking advantage of the full power and flexibility of the language, and then use Managed Extensions to write thin, high-performance wrappers that make your C++ code accessible to .NET Framework components.
You can call a C++ class from any .NET-compatible language by writing a simple wrapper class using Managed Extensions that exposes your C++ class and methods as a managed class. The wrapper acts as a mapping layer between the managed class and the unmanaged C++ class-it simply passes method calls directly into the unmanaged class. Managed Extensions support calls to any unmanaged DLL, library, or class.
You can call a .NET Framework class from your C++ code. In addition, you can write C++ code that treats a .NET Framework class like any other managed C++ class. You can also use the unmanaged COM support in the .NET Framework to call .NET Framework classes.
The Visual C++ compiler translates data, pointers, exceptions, and instruction flow between managed and unmanaged contexts. This process allows managed code to interoperate seamlessly with unmanaged C++ code. You can choose whether a class or function is managed or unmanaged. This flexibility is necessary for code or data that performs better in an unmanaged environment. However, managed code typically offers enhanced productivity, with features such as garbage collection and managed class libraries.