Migrating Unmanaged Legacy Code

   

Inevitably there will come a time when you need to migrate legacy code to the .NET Framework. You have several options as to how to proceed, including migration, and you will have to decide which is the best method for each circumstance. Performing the migration in steps allows you to take smaller steps without having to redevelop the entire application all at once, which is not generally acceptable in real-world situations.

If all your legacy code is already in C++, the managed extensions will help you make a smooth transition to the .NET platform, because you can mix the unmanaged code with the managed code as you transition it. This allows you to take one component at a time and transition it to the .NET Framework while taking full advantage of the managed code. You can write thin managed wrappers for your legacy code in order to make working with the unmanaged code as seamless as possible.

Accessing Unmanaged C++ from .NET

Managed extensions allow you to use a C++ class from any .NET language by writing a simple wrapper for the C++ class using the managed extensions. With a wrapper, any of the .NET languages can use the unmanaged C++ class because the wrapper provides a fully managed interface and acts as a mapper between the .NET language and the unmanaged C++ class.

Accessing Managed .NET Code from Unmanaged C++ Code

Accessing managed code from unmanaged code can be done by directly calling the managed class from C++ or by using the built-in Component Object Model (COM) support in the .NET Framework. Either method has its advantages and disadvantages, and choosing the right one will depend on your particular application. The COM interface is flexible and callable from other components, whereas calling the managed classes directly provides better performance and integration.

Because the Visual C++ compiler translates data, pointers, exceptions, and instruction flow between the managed and unmanaged portions of your application transparently, combining managed and unmanaged C++ code within a single executable is relatively simple.


   
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