简体   繁体   English

合并vc ++和c ++构建器项目

[英]Merging a vc++ and a c++ builder project

I am facing a situation where I have two different c++ projects : 我面临的情况是我有两个不同的c ++项目:

  • The first one is a VS2008 plugin : a DLL statically linked to MFC which I will incorporate to a certain software. 第一个是VS2008插件:静态链接到MFC的DLL,我将其结合到某些软件中。

  • The second one is a C++ Builder VCL program : A program which has a huge GUI made using the VCL. 第二个是C ++ Builder VCL程序:使用VCL制作的具有巨大GUI的程序。

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. 我一直在寻找一种将VC ++和c ++构建器项目合并的方法后,我有些沮丧。 The compatibility issues are enormous ! 兼容性问题是巨大的! especially that both MFC and VCL are involved in my case. 特别是在我的案例中同时涉及到MFC和VCL。 "migrating" from either sides seems impossible to me, especially that I'm new to programming on a Microsoft system. 在我看来,从任何一方进行“迁移”似乎都是不可能的,尤其是对于我在Microsoft系统上进行编程是不熟悉的。 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 ! 并预先感谢您!

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. 如果要与C ++类接口,请确保传递的数据只是基本的c ++类型,接口中不允许使用STL,MFC或VCL。

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. 创建两个C函数,一个是MFC类的新函数,但返回接口类,另一个是从接口指针中删除,但实际上是删除其后的MFC类。

As a quick example (just whipped up here, not tested) of the sample .h file. 作为示例.h文件的快速示例(此处只是提示,未经测试)。 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). 我反过来非常一致地做到这一点(用C ++ Builder编写代码,该代码可以用VC6编写的古老MFC应用程序中使用)。

Interface file (included in the C++ Builder code and MFC code) 接口文件(包含在C ++ Builder代码和MFC代码中)

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 仅VC端包含的MFC文件

class cInterface : public iInterface
{
   public:
      unsigned short __stdcall  DoOneThing( char * );
      long __stdcall  DoTwoThing( char * );

   private:
      void WhatEver( void );

      bool x;
}

When you have to completely different run-time environment like Basic and C++ or VCL and MFC you need to define an interface that all modules can use. 当您必须使用完全不同的运行时环境(例如Basic和C ++或VCL和MFC)时,您需要定义一个所有模块都可以使用的接口。 You're not the first programmer that hits this problem. 您不是第一个遇到此问题的程序员。 One choice that works for decades on Windows is the Component Object Model (COM). 在Windows上运行数十年的一种选择是组件对象模型(COM)。

There are a lot of COM Turtorials in the Internet. 互联网上有很多COM教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM