如何获取当前的terminate()处理程序而不改变它? [英] How can I retrieve current terminate() handler without changing it?

查看:181
本文介绍了如何获取当前的terminate()处理程序而不改变它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是问题。我的应用程序调用 CoCreateInstance()创建在第三方DLL中实现的COM对象。该DLL调用 set_terminate()更改 terminate()处理程序并传递自己的地址<$ c $ c>

Here's the problem. My application calls CoCreateInstance() to create a COM object implemented in a third-party DLL. That DLL calls set_terminate() to change the terminate() handler and passes an address of its own terminate() handler there.

$ terminate()不是由库保存 - 它不在乎,只是更改处理程序,从不恢复它。一旦DLL被卸载,它的代码不再在进程内存中,所以如果现在 terminate()被调用,程序运行到未定义的行为。

The initial terminate() handler address is not saved by that library - it doesn't care and simply changes the handler and never restores it. As soon as the DLL gets unloaded its code is no longer in the process memory, so if now terminate() is called the program runs into undefined behavior.

我想检索并存储初始 terminate()处理程序的地址,以便能够恢复它。

I'd like to retrieve and store the address of initial terminate() handler to be able to restore it. How can I do it?

推荐答案

标准C ++没有内置方式。

Standard C++ provides no built-in way.

当然你可以调用terminate()两次:第一次与任何虚拟处理程序你有(然后存储处理程序terminate()返回你);第二 - 恢复刚刚存储的处理程序;)简单的技巧。

Of course you could just call terminate() twice: first time with whatever dummy handler you have (and then store handler that terminate() returned you); second -- to restore handler you've just stored ;) Simple trick.

这篇关于如何获取当前的terminate()处理程序而不改变它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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