• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >vc/mfc > CoInitializeExNULL,COINIT_MULTITHREADED和文件对话框,解决问题者另赠送100分

CoInitializeExNULL,COINIT_MULTITHREADED和文件对话框,解决问题者另赠送100分

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-04

佚名通过本文主要向大家介绍了 CoInitializeExNULL,COINIT_MULTITHREADED和文件对话框,解决问题者另赠送100分等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: CoInitializeExNULL, COINIT_MULTITHREADED 和文件对话框,解决问题者另赠送100分
描述:

程序中调用
CoInitializeEx(NULL, COINIT_MULTITHREADED)
后再调用GetOpenFileName 或 GetSaveFileName 或 mfc 的CFileDialog,都有可能出现程序死锁文件对话框无法弹出的情况。并且这种情况在某些机器上会出现,在另一些机器上就不出现,机器硬件相同,和操作系统也没关系,同样的系统,同样的硬件,一台上有问题,另一台上就没问题,十分困惑。
谁能帮我解决问题,将另外赠送100分,更多也行,我有的是分。


解决方案1:

PRB: Oleaut32 Hidden Window Blocks Apps Broadcasting Messages
ID: Q189427 
 
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Win32 Software Development Kit (SDK)
--------------------------------------------------------------------------------
SYMPTOMS
An application that calls certain OLE Automation functions can block the global broadcast of Windows messages. For example, when a user double- clicks a desktop icon, the program associated with the icon might be blocked from starting and Windows Explorer might hang. 
CAUSE
Certain Automation APIs (example:VariantChangeType) cause OLEAut32.dll to create a hidden top-level window that processes the WM_WININICHANGE message (for example, to get notifications like time zone changes, and so forth). This is used to invalidate OLE Automation's national language setting (NLS) cache. If the thread that called this function does not service the message queue, the hidden top-level window is starved of messages. Any global broadcast of messages using the SendMessage API will cause the broadcasting application to block indefinitely. Under the MTA programming model, a thread is not obligated to service the message queue. Hence an MTA thread that calls these Automation APIs can cause this problem. 
RESOLUTION
There is no fixed set of OLE Automation APIs that create the hidden top- level window. However, the hidden top-level window is created the first time Ole Automation runtime needs to look at the NLS information. To work around this, spin a secondary thread and call an OLE Automation API first on the secondary thread (for example, VariantChangeType, changing from BSTR). This creates the hidden top-level window the secondary thread, and then pumps messages on the secondary thread. As a result, the hidden top- level window does not block broadcast messages. You can continue to use your automation methods in other threads. Send a WM_ QUIT message or use another form of inter-thread communication from the primary thread to end the secondary thread. 
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available. 
MORE INFORMATION
Steps to Reproduce Behavior
Use the following code to develop a console application: 
Sample Code
    #define _WIN32_DCOM
    #include <windows.h>
    void main()
    {
   CoInitializeEx(NULL, COINIT_MULTITHREADED);
   VARIANT var,var1;
   VariantInit(&var);
   VariantInit(&var1);
   BSTR str = SysAllocString(L"Test");
   var.vt = VT_BSTR;
   var.bstrVal = str;
   VariantChangeType(&var, &var, 0, VT_I2);
   VariantClear(&var);
   VariantClear(&var1);
   while (1)
   {
      ;
   }
   CoUninitialize();
    } 
Run this application. Run another application that broadcasts a message (for example, double click a .doc icon on the desktop). A message is broadcast to all the top-level windows that are using either SendMessage or a non-blocking variation of the SendMessage API (such as SendMessageTimeout). The broadcasting application is either blocked (hung) indefinitely or hung for the period of time it takes the call to timeout. 
One work around for the problem is to create a secondary thread from the primary thread. After you have done this, call an automation method on the secondary thread's procedure (the secondary thread will create the hidden top-level window). Create a message loop to process the messages in the secondary thread. After everything is finished, close the secondary thread from the primary thread. Since there is a message pump in the secondary thread, any broadcasted message will be processed. 
Sample Code
   #define _WIN32_DCOM
   #include <windows.h>
   HANDLE g_EventHandle;
   DWORD WINAPI SecondaryThread(LPVOID pInputParam)
   {
      HRESULT hr = S_OK;
      //&nb

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • CoInitializeExNULL,COINIT_MULTITHREADED和文件对话框,解决问题者另赠送100分

相关文章

  • 2017-06-04 MFC开发OCX控件菜鸟问题,如何在OCX中插入对话框,并能在上面添加事件控件
  • 2017-06-05 dll钩子中为什么无法将钩子释放?请看里面-->
  • 2017-06-05 高分求关于dll编程的书籍和文章
  • 2017-06-04 作一个ATL计算数字老出问题谁来教教我
  • 2017-06-05 如何产生应用程序,他在应用管理其中的用户名中可以是System,LocalService,NetworkService
  • 2017-06-04 关于调用COM+的问题
  • 2017-06-05 线程注入不稳定(分不是问题)
  • 2017-06-05 结构体DISPPARAMS的一点疑问
  • 2017-06-05 用VC++写一个很简单的IE插件
  • 2017-06-04 请教一下,Duilib中换肤的问题。会的可以指导一下吗?感激啊

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 我用Office自带的SELFCERTEXE,做证书,但出错,不知到什么原因?
    • 如何在ATL/WTL中实现打印及打印预览?
    • 如何正确的关闭线程
    • MSMQsendmessage
    • MFC修改SQL数据库自增长表出现修改问题。
    • 请教,settimer的问题
    • 关于多线程!!
    • 怎样截获IE下载的文件?
    • 关于ActiveX控件如何实现Socket的UDP接收数据功能
    • VCmapX中画点、画线的问题

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有