gpt4 book ai didi

windows - 为什么 AddVectoredExceptionHandler 会使我的 DLL 崩溃?

转载 作者:可可西里 更新时间:2023-11-01 09:59:05 25 4
gpt4 key购买 nike

我尝试将矢量异常处理添加到我的 Win32 DLL,但是对 AddVectoredExceptionHandler 的调用永远不会回来。我只是得到无用的 <app name>.exe has stopped working对话。但是,如果我使用 Visual C++ 调试器调试 dll,那么它确实可以工作,并且在适当的时间调用处理函数,一切都很好。

明确地说,我在 DLL 初始化时添加处理程序,就像这样

OutputDebugString("before adding\n");
AddVectoredExceptionHandler( 1, VectoredExcepHandler );
OutputDebugString("after adding\n");

当不通过调试器运行时,DebugView 显示“添加前”而不是“添加后”。

处理程序本身如下所示:

static LONG CALLBACK VectoredExcepHandler( PEXCEPTION_POINTERS exInfo )
{
OutputDebugString("reached handler\n");
return EXCEPTION_CONTINUE_SEARCH;
}

哦,如果重要的话,我正在运行 Vista Home 64。

事件查看器显示错误是 kernel32.dll 中的访问冲突。


更多的发现几乎解决了这个问题:我发现如果我注释掉 OutputDebugString调用处理程序,错误消失了。所以我想有一些与 OutputDebugString 不兼容的异常.显然它不是我可能想要检查的常见问题之一,例如访问冲突和无效指令,因为如果我在调用 OutputDebugString 之前检查这些异常代码, 一切顺利。

最佳答案

OutputDebugString 在调用时引发异常。所以你的异常处理程序通过调用它导致无限递归,这会导致堆栈溢出。参见 here了解更多详情。

Internally, a debug string is handled as an exception. OutputDebugString calls RaiseException with DBG_PRINTEXCEPTION_C (defined as 0x40010006) and the string address and size as the exception parameters.

关于windows - 为什么 AddVectoredExceptionHandler 会使我的 DLL 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25634376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com