在C中的Windows-DLL写入中捕获异常 [英] Catch exceptions in a windows-DLL writte in C

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

问题描述

问候!



我已经将一个C模块从linux共享对象移植到Windows DLL。

一切正常但除此之外信号捕获我正在使用linux-c显然无法在Windows DLL中工作。



我尝试过SetUnhandledExceptionFilter()但这在DLL中也不起作用。



任何提示?

解决方案

SetUnhandledExceptionFilter不起作用,因为它只会捕获有异常的异常没有其他处理程序。

因为运行时已经设置了所有管理职责的执行,所以你的代码中没有陷阱。

使用它也是不明智的那些可以卸载的DLL(比如那个用户加载或可移动),因为在这种情况下,如果库不再在内存中,处理程序仍将引用之前设置的地址,从而导致在不存在的代码中调用。

编写DLL时使用相同的注意事项,也许您可​​以使用AddVect oredExceptionHandler()。

有关用法示例,请参阅此处

Greetings!

I've ported a C-module from linux shared object to windows DLL.
All works fine except that signal trapping I'm using with linux-c apparently does not work in a windows DLL.

I tried SetUnhandledExceptionFilter() but this also does not work within a DLL.

Any hints?

解决方案

SetUnhandledExceptionFilter don't work because the it will trap only exceptions that have no other handler.
Because the runtime already set the catching of all execptions for housekeeping duties you will get no trapping in your code.
It is also not wise to use in shuch DLL's that could be unloaded (like that user loaded or removable) because in this case if the library is no more in memory the handler will still refer to the address set previously resulting a call in unexistent code.
Using same care when coding a DLL, maybe you can use AddVectoredExceptionHandler().
For usage sample see here.


这篇关于在C中的Windows-DLL写入中捕获异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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