可托管和非托管C ++ / MFC可以在一个DLL中混合使用吗? [英] Can managed and unmanaged C++/MFC be mixed in one dll?

查看:178
本文介绍了可托管和非托管C ++ / MFC可以在一个DLL中混合使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previously我们在MFC(VC6)的软件,需要调用C ++编写的(和MFC)相同的发动机VB6和C#应用程序。该发动机所需的C ++的速度。当时我们决定使用COM的接口,因为所有这三个可以在编组等方面的问题,至少使用它。

我们的MFC应用程序现在是很precated和我们最近决定抛售VB6,所以我们得到了什么左边是C#。

我们可以仅保留COM引擎 - 是的,但它会很高兴摆脱COM注册等,并有一个管理界面的工作。 COM注册偶尔会导致支持方面的问题,如果有什么问题的人的机器。

是否有可能与现有的非托管C ++ / MFC和.NET前端接口一个dll?

解决方案

您可以使用MFC类内部一个C ++ / CLI DLL。一个很好的优势,以混合模式DLL的创建与C ++ / CLI是,你可以使用本机C ++只是内部的DLL任何地方(下面的C ++ / CLI规则)和它只是工作。

这里的目标,但是,应该提供可以从C#应用程序调用漂亮,干净,托管包装。

话虽这么说 - 你很可能希望避免使用MFC的任何用户界面元素。虽然可以承载在C#中,反之亦然MFC的内容,它往往是有问题的 - 你最好只用C封装C ++引擎(时间关键的操作),并在漂亮的,干净的托管包装遗留code ++ / CLI <。 / P>

Previously we had software in MFC (VC6), VB6 and C# applications that needed to call the same engine written in C++ (and MFC). The engine required C++ for speed. At the time we decided to use COM as the interface because all three could use it with the least issues in marshalling, etc.

Our MFC application is now deprecated and we have recently decided to dump VB6, so what we've got left is C#.

We can just leave the COM engine as-is, but it would be nice to get away from COM registration, etc., and have a managed interface to work with. COM registration occasionally causes support issues if there is something wrong with the person's machine.

Is it possible to have a dll with the existing unmanaged C++/MFC, and a .NET front end interface?

解决方案

You can have a C++/CLI DLL that uses MFC classes internally. One nice advantage to mixed-mode DLL creation with C++/CLI is that you can use native C++ just about anywhere within the DLL (following the C++/CLI rules) and "it just works".

The goal here, however, should be to provide nice, clean, managed wrappers that can be called from your C# application.

That being said - you'll most likely want to avoid using MFC for any user interface elements. Though possible to host MFC content in C# and vice versa, it often is problematic - you're better off just encapsulating the C++ engine (time critical operations) and legacy code in nice, clean managed wrappers using C++/CLI.

这篇关于可托管和非托管C ++ / MFC可以在一个DLL中混合使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆