English 中文(简体)
在C/C中捕获DLL崩溃++
原标题:Catching a DLL crash in C/C++

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

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

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

在某些情况下,我传递给DLL函数的数据会导致DLL崩溃。有没有可能捕捉到这一点,这样我的应用程序就不会崩溃(而不修改不是我创建的DLL)?

最佳回答

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

问题回答

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?

如果只使用有效数据调用函数,难道不可能防止dll崩溃吗?无论如何,这应该是最好的解决方案,但如果不知道要使用哪个dll,就很难判断。但在大多数情况下,你应该知道什么“数据”会导致崩溃。。。

尝试查看:

http://msdn.microsoft.com/en-us/library/ms680634%28v=vs.85%29.aspx

Oleg Starodumov(www.debuginfo.com)强制执行筛选器代码

http://www.debuginfo.com/articles/debugfilters.html

However, that is a top level filter 和 not a try/catch. You can perhaps restart your process.

You might need to use __try for exceptions. Again, probably better to fix the problem or just crash than to try to catch it. I agree with the others that rather than suppressing or hiding the crash you should fix it. I don t know how well you can recover from the crash - is it going to be useful to continue execution after something like that?

我不确定这是否是问题所在,请尝试指定正确的调用约定。(__stdcall__ cdecl等)。

如果这不是问题所在,我们需要看看你传递给函数的是什么,如果你有函数代码的话,可能还有函数代码。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签