Catching a DLL crash in C/C++(在 C/C++ 中捕获 DLL 崩溃)
问题描述
我正在从 DLL 中调用一个函数,如下所示:
I'm calling a function from a DLL, like this:
__declspec ( dllimport ) bool dll_function(...);
int main() {
[...]
if (dll_function(...)) {
[...]
}
}
在某些情况下,我传递给 DLL 函数的数据会导致 DLL 崩溃.是否有可能捕捉到这一点,这样我的应用程序也不会崩溃(不修改不是我创建的 DLL)?
In some cases, the data I pass to the DLL function will lead to a crash of the DLL. Is it possible to catch this so my application doesn't crash as well (without modifying the DLL which is not created by me)?
推荐答案
您可以在 MSVC 编译器中使用 __try 和 __except 关键字捕获 AV.不是那么有用,你不知道造成了什么样的损害.您的程序的状态很可能已损坏.例如,堆可能被炸毁,导致随后的随机故障.将 DLL 托管在自己的进程中并使用 IPC 与其通信是唯一合适的方法.
You can catch AVs with the __try and __except keywords in the MSVC compiler. Not all that useful, you have no idea what kind of damage was done. The state of your program might well be corrupted. The heap might be blown for example, causing subsequent random failure. Hosting the DLL in its own process and using IPC to talk to it is the only decent approach.
这篇关于在 C/C++ 中捕获 DLL 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C/C++ 中捕获 DLL 崩溃
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
