如何捕获 C++/Windows 中的每个异常?

发布于 2024-11-09 17:26:35 字数 173 浏览 0 评论 0原文

我有一个 DLL,它被注入到非常旧的、有缺陷的、现在不受其开发应用程序支持的 DLL 中。有时应用程序会崩溃,我需要某种方法来捕获可能发生的所有未处理的异常(来自 DLL),以保存数据,然后才允许应用程序崩溃。我怎样才能做到这一点?

目前,有一个用于此目的的外部调试器,但它太慢了,而且还存在缺陷,无法保持这种状态。

I have a DLL that's being injected into very old, buggy and now unsupported by it's developer application. Sometimes that application crashes, and I need some way to catch literally all unhandled exceptions (from DLL) that may occur to save data and only then allow the app to crash. How can I achieve that?

For now, there is an external debugger for that purpose, but it's just too slow and also buggy to keep it that way.

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

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

发布评论

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

评论(1

年少掌心 2024-11-16 17:26:35

您必须启动一个托管 DLL 的新进程。如果 DLL 将崩溃,无论您是否愿意,它都会导致进程崩溃。当然,您可以尝试捕获异常或类似的东西,但如果抛出异常,则意味着内存已损坏。 灾难性崩溃比让程序继续运行要好在不一致的状态下运行。

Windows shell 是一个实际上执行此操作的程序 - 它在代理进程中启动一些插件,因此如果插件崩溃,它不会导致整个 shell 崩溃。您需要使用进程间通信来在您自己和您启动的代理之间进行通信。

You have to start a new process which hosts the DLL. If the DLL is going to crash, it's going to bring down the process, whether you like it or not. Sure, you could attempt to catch an exception or something like that, but if the exception is being thrown, that means memory is corrupted. It is better to crash catastrophically than to have the program continuing to run in an inconsistent state.

The windows shell is a program which actually does this -- it launches some plugins in a surrogate process, so that if the plugin crashes, it doesn't bring down the whole shell. You'd need to use interprocess communication to communicate between yourself and the surrogate you start.

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