在C / C ++中捕获DLL崩溃 [英] Catching a DLL crash in C/C++

查看:180
本文介绍了在C / C ++中捕获DLL崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从DLL调用函数,如下所示:

  __ declspec(dllimport)bool dll_function(... ); 

int main(){
[...]
if(dll_function(...)){
[...]
}
}

在某些情况下,我传递给DLL函数的数据将导致DLL崩溃。

解决方案

是否可以捕获此错误,以使我的应用程序也不会崩溃(无需修改不是由我创建的DLL)?

解决方案

您可以在MSVC编译器中使用__try和__except关键字捕获AV。没那么有用,您不知道进行了哪种损坏。您的程序状态很可能已损坏。例如,堆可能被炸毁,从而导致随后的随机故障。在自己的进程中托管DLL并使用IPC与之交谈是唯一不错的方法。


I'm calling a function from a DLL, like this:

__declspec ( dllimport ) bool dll_function(...);

int main() {
  [...]
  if (dll_function(...)) {
    [...]
  }
}

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)?

解决方案

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崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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