Search code examples
c#c++migrationc++-clivisual-studio-6

Recommended migration strategy for C++ project in Visual Studio 6


For a large application written in C++ using Visual Studio 6, what is the best way to move into the modern era?

I'd like to take an incremental approach where we slowly move portions of the code and write new features into C# for example and compile that into a library or dll that can be referenced from the legacy application.

Is this possible and what is the best way to do it?

Edit: At this point we are limited to the Express editions which I believe don't allow use of the MFC libraries which are heavily used in our current app. It's also quite a large app with a lot of hardware dependencies so I don't think a wholesale migration is in the cards.

Edit2: We've looked into writing COM-wrapped components in C# but having no COM experience this is scary and complicated. Is it possible to generate a C# dll with a straight-C interface with all the managed goodness hidden inside? Or is COM a necessary evil?


Solution

  • Faced with the same task, my strategy would be something like:

    1. Identify what we hope to gain by moving to 2010 development - it could be

      • improved quality assurance: unit testing, mocking are part of modern development tools
      • slicker UI: WPF provides a modern look and feel.
      • productivity: in some areas, .NET development is more productive than C++ development
      • support: new tools are supported with improvements and bugfixes.
    2. Identify which parts of the system will not gain from being moved to C#:

      • hardware access, low-level algorithmic code
      • pretty much most bespoke non-UI working code - no point throwing it out if it already works
    3. Identify which parts of the system need to be migrated to c#. For these parts, ensure that the current implementation in C++ is decoupled and modular so that those parts can be swapped out. If the app is a monolith, then considerable work will be needed refactoring the app so that it can be broken up and select pieces reimplemented in c#. (It is possible to refactor nothing, instead just focus on implementing new application functionality in c#.)

    4. Now that you've identified which parts will remain in C++ and which parts will be implemented in c#, (or just stipulate that new features are in c#) then focus turns to how to integrate c# and c++ into a single solution

      • use COM wrappers - if your existing C++ project makes good use of OO, this is often not as difficult as it may seem. With MSVC 6 you can use the ATL classes to expose your classes as COM components.
      • Integrate directly the native and c# code. Integrating "legacy" compiled code requires an intermediate DLL - see here for details.

    Mixing the MFC UI and c# UI is probably not achieveable, and not adviseable either as it would produce a UI mix of two distinct styles (1990s grey and 2010 vibe). It is simpler to focus on achieving incremental migration, such as implementing new application code in c# and calling that from the native C++ code. This keeps the amount of migrated c# code small to begin with. As you get more into the 2010 development, you can then take the larger chunks that cannot be migrated incrementally, such as the UI.