Search code examples
c++visual-c++mfcc++buildervcl

Merging a vc++ and a c++ builder project


I am facing a situation where I have two different c++ projects :

  • The first one is a VS2008 plugin : a DLL statically linked to MFC which I will incorporate to a certain software.

  • The second one is a C++ Builder VCL program : A program which has a huge GUI made using the VCL.

My mission is to incorporate the second one in the first (the plugin) so that once I charge the plugin in the software I mentioned before, I would be able to launch that second program, process data using it, and save the changes. so I need to be able to use methods and classes from both projects together ...

I got a little depressed after I've been searching for a way to merge a VC++ and a c++ builder project. The compatibility issues are enormous ! especially that both MFC and VCL are involved in my case. "migrating" from either sides seems impossible to me, especially that I'm new to programming on a Microsoft system. So I would be happy if there was an alternative.

So I'm asking you for your help fellow developpers, especially those who have faced a similar situation. I would be grateful for any type of answer.

Feel free to ask me any questions to clearify this post.

And thank you in advance !


Solution

  • If you are interfacing with C++ classes, make sure that the data passed are only basic c++ types, no STL or MFC or VCL allowed in the interface.

    Then, you can create a pure virtual class of the interface class, derive the interface class from the pure virtual class. Create two C functions, one that new's the MFC class but returns the interface class and one that delete from the interface pointer but actually deletes the MFC class behind it.

    As a quick example (just whipped up here, not tested) of the sample .h file. This works by virtue of the virtual interface being the same between the two compilers. I do it very consistently in reverse (write code in C++Builder that can be used in an ancient MFC application written in VC6).

    Interface file (included in the C++ Builder code and MFC code)

    class iInterface
    {
       public:
          virtual unsigned short __stdcall DoOneThing( char * ) = 0;
          virtual long __stdcall DoTwoThing( char * ) = 0;
    }
    
    iInterface * __stdcall NewcInterface();
    void __stdcall DeletecInterface( iInterface * );
    

    MFC file included in VC side only

    class cInterface : public iInterface
    {
       public:
          unsigned short __stdcall  DoOneThing( char * );
          long __stdcall  DoTwoThing( char * );
    
       private:
          void WhatEver( void );
    
          bool x;
    }