Microsoft KB Archive/194220

= PRB: Windowless ATL, MFC Controls Work in Internet Explorer 3, Fail in 4.0 =

Article ID: 194220

Article Last Modified on 5/11/2006

-

APPLIES TO

 Microsoft Internet Explorer 4.0 128-Bit Edition Microsoft Internet Explorer 4.01 Service Pack 2 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li> Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q194220

<div class="symptoms_section">

SYMPTOMS
The debug build of an ActiveX control written in MFC or ATL displays an ASSERT on a line in MFC: ASSERT(::IsWindow(m_hWnd));

In ATL the following appears: ATLASSERT(::IsWindow(m_hWnd)); A release build of the ActiveX control may crash with an Access Violation or not work properly.

Also, the COleControl::OnCreate or WM_CREATE message handler for the control may unexpectedly fail to fire.

These symptoms occur specifically when the control is hosted in Internet Explorer 4.0x or later but do NOT occur when the control is hosted in Internet Explorer 3.0x.

<div class="cause_section">

CAUSE
The ActiveX control has been declared to be windowless but calls framework functions that require a window or the control otherwise assumes the existence of a window. The OnCreate method is called only when a window is created, and code in this method will not execute if the control is windowless.

Internet Explorer 3.0x is not a windowless control container, so windowless controls get created with a window anyway when hosted in HTML pages. Internet Explorer 4.x is, on the other hand, a true windowless control container. The mistake in the control is hidden by Internet Explorer 3.0x's container support, only to be revealed when tested against Internet Explorer 4.0x or later.

ATL controls are windowless by default. In ATL, it is much easier for a control author creating a control for Internet Explorer 3.0x to code the entire control under the mistaken assumption that the control is windowed.

MFC controls are windowed by default, but based on the choices made during the Control Wizard, could be accidentally set to be windowless.

<div class="resolution_section">

RESOLUTION
Move necessary code out of the OnCreate/WM_CREATE handler and redesign the control to not require a window. Do not call MFC or ATL functions that require windows, particularly those that result in the ASSERT described in SYMPTOMS above.

-or-

Change the control to be windowed instead of windowless. In an ATL control, set CComControlBase::m_bWindowOnly to TRUE in the CComControl object's constructor. In an MFC control, remove "windowlessActivate" from the dwFlags enumeration returned from the GetControlFlags method.

The latter is preferred because by the time this problem is observed, the control has probably already been coded from the ground up to assume the existence of a window.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
This article equally applies to any other windowless control container.

If the ActiveX control is not marked as windowless but still shows similar problems when hosted in Internet Explorer 4.0x or later, it is a different issue from the one discussed in this article.

<div class="references_section">