The Relationship Between Managed and Unmanaged Code

   

Unmanaged code is what you have been writing with Visual C++ and MFC. Therefore, unmanaged code is the same type of application you are already used to. Managed code, on the other hand, is code that is written and compiled for the .NET Framework and runs with the help of the CLR.

Managed and unmanaged code have a common relationship in that they both resolve down to using the Win32 API at their lowest state. The differences arise in how the source code is written and structured as well as how the applications that are built run within the environments for which they were created. Figure 5.1 shows the relationship between managed and unmanaged code within a single executable.

Figure 5.1. The relationship between managed and unmanaged code.

graphics/05fig01.gif

Typically unmanaged Visual C++ applications are written with either the MFC, ATL, or C runtime library or a mixture of more than one of these libraries. Ultimately, all unmanaged code written for the Windows platform uses the Win32 API to work with the operating system.

In contrast, all managed code is written for the .NET Framework and is based solely on the .NET Framework. Therefore, it must use the classes provided through the .NET Framework for development and does not access the Win32 API directly. Anytime code outside the .NET Framework is accessed, that portion of code is run as unmanaged. For example, a managed class written for the .NET Framework can use an unmanaged class.

However, when a program is executing code within the unmanaged class, all the features of managed code are not available because it is running in unmanaged mode without the help of the CLR.


   
Top


Sams Teach Yourself Visual C++. NET in 24 Hours
Sams Teach Yourself Visual C++.NET in 24 Hours
ISBN: 0672323230
EAN: 2147483647
Year: 2002
Pages: 237

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net