KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q305723: PRB: COM Application Hangs When CoCreateInstance Is Called from

Article: Q305723
Product(s): Microsoft Programming Utilities
Version(s): 
Operating System(s): 
Keyword(s): 
Last Modified: 09-MAY-2002

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft COM 
-------------------------------------------------------------------------------

SYMPTOMS
========

When you call the CoCreateInstance function from the DllMain function, the
Component Object Model (COM) application hangs.

CAUSE
=====

CoCreateInstance may start a thread that tries to call the DllMain function of
all dynamic-link libraries (DLLs) that exist in the process by passing a
DLL_THREAD_ATTACH value. Because the call originates from DllMain, and because
DllMain is not a reentrant function, the call to CoCreateInstance never returns.

RESOLUTION
==========

To resolve this problem, do not call CoCreateInstance from DllMain. You can move
the call to an initialization function or to any other function that is called
later.

STATUS
======

This behavior is by design.

Additional query words:

======================================================================
Keywords          :  
Technology        : kbAudDeveloper kbCOM kbCOMPlusSearch kbComSearch
Version           : :
Issue type        : kbprb
Solution Type     : kbnofix

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.