What are some techniques for migrating a large MFC application to WPF/.NET? What are some techniques for migrating a large MFC application to WPF/.NET? wpf wpf

What are some techniques for migrating a large MFC application to WPF/.NET?


Revisiting this because I have successfully replaced our top level MFC UI (the main frame, windows, and toolbars) with WPF.

As it turns out, our core drawing code merely needs to be handed an HWND to render into. This made it really easy to reuse the bulk of our existing C++ codebase.

Here's a quick rundown on the key pieces of the approach I took:

  • Used the .NET HwndHost class to host an HWND for the C++ drawing code to render into
  • Created C++/CLI wrappers for any native C++ code that needed to be exposed to the WPF/C# UI code
  • Left most of the MFC dialogs as-is in the native C++ code. This minimizes the amount of work needed to finish the UI. The MFC dialogs can be migrated to WPF over time.

As a side note, we're using SandDock and SandRibbon from Divelements and have been very happy with them so far.


I don't think there's an easier way that you've not covered, although it will probably depend quite a bit on how well separated the underlying logic is from the UI layer.

Without wishing to seem negative: are you sure that this will be worth the effort? If I were writing a large application from scratch I wouldn't start with C++ and MFC now, but seeing where you are, what will you really gain from rewriting it? Will that add a single new feature that users will pay for? Are there any users you'll cut off who won't be able to run the new version? I can't help suspecting you'll get a much bigger return on investment from looking at some relatively simple things you could do to improve the appearance of the application as it is. For example, does it have an XP-style manifest so that common controls get the XP look? Would a few days spent updating bits (e.g. using the new style file dialogs) get you most of the way to a shiny new look? Bear in mind that even the newest, shiniest Office 2007 was implemented by Microsoft with ordinary Win32 controls.


I had to do the same thing in a project using WinForms before. We needed to migrate our MFC project to .NET 1.1 and we decided to take all the core functionality of the MFC application and write managed wrappers around all of them. Then we wrote a WinForms front end and plugged in the legacy c++ code bit by bit. I think we made the right choice in the long run. I can't imagine how we would have done it if we had tried to preserve the MFC front end at the same time.