Friday, October 14, 2005

A solution for converting C++ MFC code to C# or VB.Net

As Program Director for the Lansing MI based Great Lakes User Group for .Net (, I received an email from a member that has found a very useful method to accomplish a needed conversion from MFC C++ code into C# or VB.Net. While C++ MFC is outside my area of expertise, I read through his explanation and it sounds like a very useful technique. For those who can benefit, I have included the text of his email below. If you wish to explore this topic further, post a comment and I'll be sure that he is asked to contact you. Thanks. Joe Kunk


As a .NET user group member I wanted to share my experience of"migrating my MFC apps to .NET using C# and VB.NET" so that it will be beneficial for all our members. It might not be an ideal solution for all but I am hopeful it will add at least few new pointers in your knowledge base.

The problem was "How to migrate MFC applications to .NET in C# orVB.NET?" and there were no guidelines or samples. As we know MFC will besupported in Windows Vista (earlier codenamed longhorn) so we can keep MFC apps running for at least few years but question was how to enhanced and use with .NET managed assemblies, keep maintenance low, less compatibility issues, less interops, less performance hiccups and less complicated install program.

Above all new customers were asking on which technology our product wasbuilt? And if answer was "MFC" then we started loosing new business opportunity. Then what to do? What is the trend? Most of C++ programmershave already moved to C# and wish to convert their apps in C# or VB.NET but again there is lack of information on how to do it.

My first problem was ATL or MFC UI conversion to Windows Form resources and there was no help and that was the reason we never went ahead with even prototype test for migration. But thanks to Google where I found acompany called DudeLabs( )which has a product"RC Converter" and it changed our migration policy because only in minutes we had our hundreds of dialogs, form views, all standard controls with their properties, menus, string resources and accelerators converted in Windows form resources and we chose our own class name,file name, namespace name and control names naming conventions. We used C# on Visual studio 2005 format but it also generates Visual studio 2003 format and supports C# and VB.NET both.

This quick conversion of our UI gave us ample time to focus on business layer and data layer rewrite.

Now thanks to Microsoft whose application block for SQL Data Access fixed our data layer rewrite in minutes because we were using MS SQLServer 2000. But even if you are using other databases please use SQLData Access application block code as sample and you will be done in hours or in worst case 2 or 3 days.

Business logic rewrite needs to be done manually and we knew that so we started rewriting it and let me tell you writing code in Visual Studio 2005 takes one third or less time as compared to MFC or ATL and then if you have any issues visit or and be assured you will find your solution there and if not the exact answer then at least you will find something to start with. I am really happy as we are near completion of our product migration from MFC to .NET managed world.
As .NET user group and our .NET community always helped me in my migration path I wanted to share it with you all so that it will make your migration at least a little bit easier.

What I learned was - It takes less time and money to migrate to .NET from MFC/ATL than we are estimating in present scenario.

But be careful as only migration to .NET will not increase you sales immediately because this migration first makes sure that your product will survive in future and then it increase your new sales opportunities and gives you flexibility to add new functional modules with less development time, ability to interact with managed world tools and components, enhances performance, keeps you on cutting edge technology, provides you click once deployment and has a very low maintenance cost.

So what you are waiting for?

Wish you good luck with your migration!


pmed said...


We are currently trying to convert our MFC application. We are still investigation various scenarios :
- full migration
- integrating winforms in our mfc app
- integrating of mfc app in winforms

Could you give us some tip about the time it took you to convert your MFC app to a WinForm app ? A figure that interests us is the ratio (migration time) to (number of line in MFC)

Kind regards,


Macrosoft said...

Good information on conversion.

VB.Net Migration