Microsoft KB Archive/152075

= FIX: Control Container Support Only Works in Primary Thread =

Article ID: 152075

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription 

-



This article was previously published under Q152075



SYMPTOMS
When using the ActiveX control container support built into MFC, controls should only be created and used in the primary thread. The primary thread is the thread created automatically for you during startup of the MFC program. Starting other threads and trying to use MFC's built-in control container support will cause unpredictable and erratic behavior of the primary thread and any other threads that attempt to display ActiveX controls. This problem will occur whether you use a UI thread or a worker thread.



CAUSE
This situation appears to occur because the afxOccManager is stored as a process local variable.



RESOLUTION
There is no reliable workaround for this issue at this time. If your program uses ActiveX controls, make sure they are displayed in the primary thread only.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 32- bit Edition version 4.2.

<div class="moreinformation_section">

MORE INFORMATION
This situation can be reproduced by creating an Appwizard generated app that supports ActiveX control containment. Create a dialog in the first thread that displays an ActiveX control. Add a class to your project derived from CWinThread that will create a secondary thread. Also, add another dialog to the project that contains an ActiveX control that will be created as a modeless dialog by the secondary thread when the secondary thread starts up. This can be done in the CWinThread's InitInstance method. Build the app. When the app is run, if you show the dialog that contains the ActiveX control in the first thread, the second thread will no longer be able to create ActiveX controls. Conversely, if the second thread shows its dialog first, the primary thread will not be able to create ActiveX controls. If you attempt to create ocx controls in more than one thread, you will also get an access violation in OLE32.dll when the program terminates.

Additional query words: 4.00 4.10 4.20 ocx vcfixlist420 kbole MfcOLE kbSweptVC600

Keywords: kbbug kbfix kbnoupdate kbthread KB152075

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.