December 3rd, 2009, 02:07 PM
Migrating from MFC to .NET with C++.NET
Hi, i'm a C++ programmer and i wrote a lot of MFC and plain C Win32 API code.
I'd like to migrate to .NET, but being able to re-use the legacy code i've already written, without having to rewrite it entirely in a new language.
So, i think my migration process could be this, is it convenient or even possible?
1) I learn C#
2) I learn C++.NET
3) If i have to write a .NET class which does not use my old MFC+Win32 code, i'll use C#
4) If i have to use the old code, i'll use C++.NET and i'll cut-and-paste there the old MFC code (which is compatible, i hope)
The point 4 is the only reason i would learn C++.NET, but is that possible?
Last edited by GordonFreeman; December 3rd, 2009 at 02:10 PM.
December 4th, 2009, 02:49 PM
Re: Migrating from MFC to .NET with C++.NET
.NET has two UI Frameworks: Windows Forms and WPF. Both of them are not compatible with MFC UI Framework. You need to decide, what framework you want for UI building. Usually, UI is built in Windows Forms or WPF, in C# language. It is possible to do this in C++/CLI, but I don't recommend it - C++/CLI has bad IDE support, and it is too complicated. C# is much better.
Legacy code, written in C++, may be used in .NET applications. C++/CLI is used for interoperability between pure .NET languages, like C#, and unmanaged C++. C++/CLI is mostly used to write .NET wrappers for unmanaged code. Unmanaged code may be written using MFC, but without using UI elements.
Another interoperability way is using PInvoke. It allows to call unmanaged API functions from .NET languages. It works like VB6 API calls.
If you want to keep MFC as UI framework, and use some .NET classes, compile existing application with /CLR switch. This allows to use any .NET class from C++ code, which is actually C++/CLI, once compiled with /CLR.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.