DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 287087 - Last Review: June 19, 2014 - Revision: 2.0

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.

References

"Process, Threads, and Apartments," under COM Fundamentals in the Platform SDK Documentation:
http://msdn.microsoft.com/en-us/library/ms693344(VS.85).aspx (http://msdn.microsoft.com/en-us/library/ms693344(VS.85).aspx)
Keywords: 
kbinfo kbpending kbshellgrp KB287087
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support