Migrating from MFC to .NET with C++.NET
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Migrating from MFC to .NET with C++.NET

  1. #1
    Join Date
    Mar 2005
    Location
    .NET 3.5
    Posts
    97

    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 01:10 PM.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,517

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center