Microsoft KB Archive/191355

= FIX: ATL Doesn't Call InitCommonControls in ActiveX Control =

Article ID: 191355

Article Last Modified on 12/10/2003

-

APPLIES TO

 Microsoft ActiveX Template Library 2.0, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition  Microsoft ActiveX Template Library 2.1, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

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

-

<div class="notice_section">

This article was previously published under Q191355

<div class="symptoms_section">

SYMPTOMS
An ATL ActiveX control based on one of the common controls may not appear in an ActiveX control container.

<div class="cause_section">

CAUSE
The ATL Object Wizard doesn't add a call to InitCommonControls when you insert an ActiveX control based on a common control. The call to InitCommonControls is required if you use any of the common controls in your ATL ActiveX control.

NOTE: If you didn't select "Support MFC" in the ATL Object Wizard when creating your project, then you must link with Comctl32.lib in order to call InitCommonControls. Otherwise, an LNK2001 linker error may occur when calling InitCommonControls.

Among the common controls, the richedit control is an exception. Instead of calling InitCommonControls, you need to do a LoadLibrary on Riched32.dll.

<div class="resolution_section">

RESOLUTION
This problem has been fixed in Visual C++ 6.0. The ATL Object Wizard adds a call to InitCommonControls for you. For richedit controls, you have to call LoadLibrary and FreeLibrary on Riched32.dll. If you're using Visual C++ 5.0 or earlier, just add the call to InitCommonControls before calling Create for the common control. The Wizard usually calls Create in OnCreate: LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam,                   BOOL& bHandled) {     RECT rc; GetWindowRect(&rc); rc.right -= rc.left; rc.bottom -= rc.top; rc.top = rc.left = 0; ::InitCommonControls;               // ADD THIS LINE m_ctlSysListView32.Create(m_hWnd, rc); return 0; } For the richedit control, you'll need to load Riched32.dll and unload it: BEGIN_MSG_MAP(CRichEdit6) MESSAGE_HANDLER(WM_DESTROY, OnDestroy) // Add this line. // ...  END_MSG_MAP

HINSTANCE m_hLibRichEdit;                // Add this line.

LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam,                   BOOL& bHandled) {     RECT rc; GetWindowRect(&rc); rc.right -= rc.left; rc.bottom -= rc.top; rc.top = rc.left = 0; m_hLibRichEdit = LoadLibrary(_T("RICHED32.DLL"));   // Add this line. m_ctlRichEdit.Create(m_hWnd, rc); return 0; }

// Add this function. LRESULT OnDestroy(UINT, WPARAM, LPARAM, BOOL&) {     m_ctlRichEdit.DestroyWindow; FreeLibrary(m_hLibRichEdit); return 0; }

<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 has been corrected in Microsoft Visual C++, 6.0.

<div class="moreinformation_section">

MORE INFORMATION
Containers such as ActiveX Control Test Container in MFC 4.2 already call InitCommonControls so this problem does not occur.

Additional query words: ocx RichEdit SysListView32 SysTreeView32 SysAnimate32 SysTabControl32 rich edit listview treeview animate tab tabcontrol tooltip header hotkey image list progress slider spin buttton

Keywords: kbbug kbfix kbvc600fix kbatl300fix kbctrlcreate kbwizard KB191355

-

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

© Microsoft Corporation. All rights reserved.