GetOpenFileName异常退出的解决办法

起源
《Windows程序设计(第五版)》第13章的PopPad例子程序:

运行PopPad程序-》File-》Open-》把鼠标悬浮在一个文件上直到出现tips-》点取消按钮-》File-》Open-》把鼠标悬浮在一个文件上直到出现tips-------》整个程序消失

记事本也有相同的问题,这是一个可以必现的bug。重现步骤:

Steps to reproduce this problem

<script type="text/javascript">loadTOCNode(2, 'moreinformation');</script>
1.On a Microsoft Windows XP SP2-based computer, you click Open, Save, or Save As on the File menu to open or to save a file in a program.
2.You click Desktop in the Open, Save, or Save As dialog box.
3.You move the mouse pointer over a file, and then close the dialog box after the tool tip file information is displayed. You open the Open, Save, or Save As dialog box again, and then move the mouse pointer over the same file.


分析与解决
在装有Adobe Acrobat Reader Version 7的XP SP2机器上会出现这个问题。
微软的
http://support.microsoft.com/kb/909486/en-us
中提供了一个临时解决办法——a hotfix,不太好。

我曾给一个帖子回复的办法:使用SEH捕获异常然后抛弃,这样不至于让程序crash掉。也不太好。

今日,再次研究这个问题,发现了一个办法:(已验证,验证程序见后)

先调用CoInitialize() 或 OleInitialize(),运行完成后,当然要调用对应的UninitXXX方法。

问题的根源在于一个pdf DLL需要COM环境。

参考:
1) http://www.ureader.com/message/821299.aspx
2) http://community.csdn.net/Expert/TopicView3.asp?id=5738517

测试例子代码:
http://download.csdn.net/source/240302
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值