Friday, April 29, 2011

wrapping an MFC Gui app into a DLL(or something else) for .NET interop

sound like a terrible idea? Yeah I thought so too. Needless to say im told I have to do it.

Situation: Old MFC-based C++ gui application that reads and processes a whole lot of data sources into an internal datastructure, before displaying it to the user.

Problem: I need that datastructure in .NET, in XML will do.

Solution:

  1. Make a function in the MFC app that writes the datastructure to a big XML string(easy).
  2. dllexport this function(or COM?)(as a C++ or C funtion or what?)
  3. Compile the MFC GUI app into a dll(how?).
  4. ???
  5. Reference the dll from .NET and P/Invoke method for great profit.

Is this insanity? Is it possible to compile a dll library from a GUI MFC app without changing it? Is it a horrible idea? What are my alternatives? Im pretty lost tbh.

From stackoverflow
  • I would be working on extracting the specific business logic code in the MFC app and sticking that stuff in a DLL, rather than trying to wrap up the whole app.

    You might be making a false assumption here that it will take you less effort to wrap the MFC app up as a DLL (basically removing all the GUI code, adding a DLL main and modifying the build process to produce a DLL), than the effort to isolate the business logic code and put that in a new DLL project.

    To wrap the GUI up as a DLL you will need a pretty good understanding of the dependencies of the business logic code and how it is used by the GUI, so you may as well just cut that stuff out.

    dalyons : that is what i would be doing also - however I cannot, because im just a contractor and they 'dont have the resources' to change the scope to include refactoring the app.
    Cannonade : I think the resources for linking the GUI app as a DLL and exposing the appropriate business logic as an exported function might be equivalent to just extracting that business logic and building a new DLL.
    Javier De Pedro : I agree with Cannonade. I don't think your approach it's going to work (I am not an expert in this kind of things though). But isolating the business logic is always a good idea (not only in this particular case) and will give you other advantages.
  • Can you change the MFC source just a little? Why not add some command-line parameters to cause the app to spit XML to std output instead of launching GUI?

    In CWinApp::InitInstance you have access to command-line paramters by inheriting CCommandLineInfo.

    From the .Net client, launch the process and capture the output.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.