CoInitializeEx()与CFileDialog等

MFC程序若采用下述语句初始化自由线程单元:
::CoInitializeEx(0,COINIT_MULTITHREADED);

应用程序将再也不能使用CFileDialog类,而其他的类还能够正常应用

Q287087

SUMMARY

When you call or access a shell function or shell interface from a thread that has been initialized as a multithreaded apartment, the function or interface may have its functionality impaired or completely fail.

MORE INFORMATION

A call to CoInitializeEx(COINIT_MULTITHREADED) allows calls to objects created on the calling thread to be run on any thread. When accessing objects that use the apartment threading model from a multithreaded apartment, COM will synchronize access to the object. In order for this synchronization to occur, COM must marshal calls to the object. Because the shell currently does not provide the necessary information, either through a type library or proxy/stub code, for its objects to be marshaled, attempts to access shell objects from a multithreaded apartment fail.

The following are examples of how calls to CoInitializeEx(COINIT_MULTITHREADED) can affect functions that rely on shell objects:

GetOpenFileName/GetSaveFileName
Users can navigate to namespace extension folders such as "My Documents" through the Open and Save As dialog boxes. However, these folders cannot be browsed to because the browser cannot create the required interfaces, such as IShellFolder.
ShellExecute/ShellExecuteEx
ShellExecute hooks can be written to extend the functionality of ShellExecute/ShellExecuteEx by implementing the IShellExecuteHook interface. When ShellExecute/ShellExecuteEx is called, registered ShellExecute hooks cannot be loaded.
In both of these examples, the component that is attempting to obtain an interface pointer to a shell object with CoCreateInstance, IUnknown::QueryInterface, and so forth will typically fail with error E_NOINTERFACE when called from multithreaded apartments. The reason, as noted above, is that there is no type information or proxy/stub code for the objects being requested.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值