托管和非托管 C++/MFC 可以混合在一个 dll 中吗?

发布于 2024-09-05 00:35:02 字数 318 浏览 4 评论 0原文

以前,我们有 MFC (VC6)、VB6 和 C# 应用程序中的软件,需要调用用 C++(和 MFC)编写的相同引擎。该引擎需要 C++ 来提高速度。当时我们决定使用 COM 作为接口,因为所有三个都可以使用它,并且在编组等方面的问题最少。

我们的 MFC 应用程序现已弃用,并且我们最近决定转储 VB6,所以我们剩下的就是 C# 。

我们可以让 COM 引擎保持原样,但最好摆脱 COM 注册等,并拥有一个可以使用的托管接口。如果用户的机器出现问题,COM 注册有时会导致支持问题。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半暖夏伤 2024-09-12 00:35:03

您可以拥有一个在内部使用 MFC 类的 C++/CLI DLL。使用 C++/CLI 创建混合模式 DLL 的一个很好的优点是,您可以在 DLL 中的任何位置使用本机 C++(遵循 C++/CLI 规则)并且“它可以正常工作”。

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

话虽这么说,您很可能希望避免对任何用户界面元素使用 MFC。虽然可以用 C# 托管 MFC 内容,反之亦然,但这通常会出现问题 - 最好使用 C++/CLI 将 C++ 引擎(时间关键操作)和遗留代码封装在漂亮、干净的托管包装器中。

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.

难忘№最初的完美 2024-09-12 00:35:03

C++/CLI 可以做到这两点。

C++/CLI can do both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文