来自 MFC 扩展 DLL 的 C++/CLI

发布于 2024-07-08 08:34:21 字数 350 浏览 6 评论 0原文

我有一个 MFC 应用程序,它使用多个 MFC 扩展 DLL。 我希望这个应用程序(以及其他几个类似的应用程序)能够访问 .net 框架的某些部分。 我编写了一个 C# 库来完成我想要的 .net 工作,并希望能够编写一个 MFC dll 来隐藏我的应用程序中的所有 C++/CLI 代码。 这些应用程序将保留为纯 MFC 应用程序,唯一的 C++/CLI 代码将位于我的新 MFX 扩展 DLL 中。 然而,当我这样做时,应用程序在访问新的 MFC C++/CLI dll 时崩溃了。 如果我将 C++/CLI 代码放入应用程序中,它就可以正常工作,并且我可以一路调试到 C#。

有谁明白为什么 dll 的想法行不通?

谢谢

I have an MFC application that uses several MFC extension DLL's. I want this app (and several other similar apps) to be able to access some parts of the .net framework. I wrote a C# library to do the .net work I want and was hoping to be able to write an MFC dll to hide all the C++/CLI code from my apps. The apps would stay as pure MFC apps and the only C++/CLI code would be in my new MFX extension DLL. However when I did this the apps crashed when accessing the new MFC C++/CLI dll. If I put the C++/CLI code in the apps it works ok and I can debug my way all the way in to the C#.

Does anyone understand why the dll idea doesn't work?

Thanks

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

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

发布评论

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

评论(3

番薯 2024-07-15 08:34:21

您无法从纯本机代码引用托管程序集。 您必须打开使用者上的 /clr 开关(在项目范围内或在某些文件中),或者进行一些互操作。

一种互操作选项允许您的消费者说纯本机正在通过 COM 可调用包装器

You can't reference managed assemblies from pure native code. You have to either flip the /clr switch on the consumer (either project-wide or in certain files,) or do some interop.

One interop option that will allow your consumer to say pure native is calling into the managed assembly via COM Callable Wrapper.

空气里的味道 2024-07-15 08:34:21

我相信我也遇到过类似的问题。 我的设置类似 - 带有纯 MFC DLL 的纯 MFC 应用程序,该应用程序又与 C++/CLI DLL 交互。 一切都会运行良好,但退出时会崩溃。 使用 CppUnit 测试纯 MFC DLL 时,问题更加严重。

在调试时,我发现由于错误,我的 C++ 代码在退出时抛出访问冲突(通过悬空指针引用的对象)的第一次机会异常。 现在,C++ 运行时在退出时会忽略这些违规行为,而 CLR 则不会。 CLR 运行时抛出未处理的异常,使得程序/单元测试看起来崩溃了。

您的问题可能有所不同,但听起来确实与我遇到的问题非常相似。

I believe I have run into a similar problem. My setup was similar - A pure MFC app with a pure MFC DLL which in turn interacted with the C++/CLI DLL. Everything would run fine, but it would crash on exit. The problem was exacerbated while testing the pure MFC DLL using CppUnit.

On debugging, I found out that due to a bug, my C++ code was throwing first-chance exceptions for access violations (objects referenced via a dangling pointer) on exit. Now, the C++ runtime ignores these violations on exit, whereas the CLR does not. The CLR runtime throws an unhandled exception making it appear that the program / unit-test crashed.

Your problem maybe different, but it does sound quite similar to the one I had.

甜嗑 2024-07-15 08:34:21

MFC dll 项目引用 C# 库,并有一个使用 /clr 编译的文件,用于处理我的 C# 库中的接口。 实际上,我有时在运行时看到过这种工作,但从未能够调试到 MFC dll 或 C# 代码中。 然而,它似乎根本不稳定,并且在大多数情况下都会崩溃。

The MFC dll project references the C# library and has one file compiled with /clr that handles the interface into my C# library. I have actually seen this work sometimes at run time but have never been able to debug into the MFC dll or into the C# code. However it doesn't seem to be at all stable and crashes in the majority of cases.

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