Microsoft KB Archive/181949

From BetaArchive Wiki

Article ID: 181949

Article Last Modified on 10/16/2003



APPLIES TO

  • Microsoft OLE 4.0, when used with:
    • Microsoft Windows 95



This article was previously published under Q181949

SYMPTOMS

Due to a bug in the RPC runtime DLLs that ship with DCOM951.1, MTA clients that do not service the message queue may block the global broadcast of DDE messages. When a user double-clicks on a desktop icon, the program associated with the icon may be blocked from launching and Windows Explorer may hang.

CAUSE

A top-level window is created by the RPC runtime on the MTA client thread that called CoCreateInstance(Ex), but the window is not destroyed when the API returns. The client thread has no obligation to service the message queue under the MTA programming model. If it does not, this top-level window causes global DDE broadcast messages to block.

RESOLUTION

To work around this bug, you need to make the client's MTA thread behave like an STA thread (that is, it must service the message queue). If it is blocking on a win32 handle, it must call the MsgWaitForMultipleObjects() API to simultaneously dispatch windows messages. See the REFERENCES section for an article that explains how to do this.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

A thread initializes COM libraries for the Single Threaded Apartment(STA) by calling CoInitializeEx(0, COINIT_APARTMENTTHREADED), or simply CoInitialize() or OleInitialize(). This type of thread must service the message queue for the following two reasons:

  • COM creates a hidden top-level window when a thread calls the APIs mentioned above. A thread must always service the message queue if it creates top-level windows. If it does not, the thread can block the global broadcast of messages by any application using the SendMessage API.
  • Incoming calls into the apartment are delivered as messages posted by COM to this hidden window. If the thread does not service the message queue, it will not receive incoming calls.

A thread initializes COM libraries for the Multi Threaded Apartment(MTA) by calling CoInitializeEx(0, COINIT_MULTITHREADED). This type of thread does not need to service the message queue, because incoming calls into this type of apartment are delivered through RPC runtime threads and not through windows messages. COM does not create any windows when the thread calls CoInitializeEx(0, COINIT_MULTITHREADED). The RPC runtime creates hidden windows as needed to facilitate calls. The RPC runtime does this on its own threads and it services the message queue. However, due to the bug described in this article, the RPC runtime creates a window on the client's thread and does not destroy this window when the call completes. If the client does not service the message queue, this top-level window will block global broadcasts.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

136885 INFO: OLE Threads Must Dispatch Messages


Keywords: kbbug kbdcom KB181949