An ATL COM dynamic-link library that registers and creates a window may cause an access violation in Windows NT or in Windows 2000 (248400)
The information in this article applies to:
- The Microsoft Active Template Library (ATL) 2.0, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- The Microsoft Active Template Library (ATL) 2.1, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- The Microsoft Active Template Library (ATL) 3.0, when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Windows NT Server 4.0
- Microsoft Windows NT Workstation 4.0
- Microsoft Windows 2000 Advanced Server
- Microsoft Windows 2000 Server
- Microsoft Windows 2000 Professional
This article was previously published under Q248400 SYMPTOMS An ATL Component Object Model (COM) dynamic-link library
(DLL) that registers and creates a window and that runs on the Windows NT or Windows
2000 operating system may cause an access violation. CAUSE ATL does not unregister the window classes that it
registers.
On a Windows 9x-based computer, all window classes that
are registered by a DLL are unregistered when the DLL is unloaded. However, in
the Windows NT and Windows 2000 operating systems, no window classes registered
by a DLL are unregistered when the DLL is unloaded. RESOLUTION Unregister all of the window classes of the windows that
you are creating inside of your ActiveX control. Use the code shown in the
"Sample Code" section to unregister the window classes in the destructor of
your class. Resolution for CContainedWindow Use If you have a CContainedWindow object in your class, the m_lpszClassName member of the CContainedWindow class stores the class name that was used to register the class.
The sample code uses the same logic that is used by ATL (in Atlwin.cpp, CContainedWindow::RegisterWndSuperclass) to construct the window class name, and uses that name to
unregister the class: Sample Code
LPTSTR szBuff = (LPTSTR)_alloca((lstrlen(m_MyContainedWnd.m_lpszClassName) + 14) * sizeof(TCHAR));
lstrcpy(szBuff, _T("ATL:"));
lstrcat(szBuff, m_MyContainedWnd.m_lpszClassName);
::UnregisterClass(szBuff, _Module.GetModuleInstance());
Replace m_MyContainedWnd with your CContainedWindow object name. Resolution for CWindowImpl Use If you have an ActiveX control or use one of the DECLARE_*
macros, use code similar to the following:
::UnregisterClass(CMyClass::GetWndClassInfo().m_wc.lpszClassName, CMyClass::GetWndClassInfo().m_wc.hInstance);
Replace CMyClass with your class name. If you have multiple
contained windows or have a contained window in a control, use both of these
resolutions, according to how you have used the contained windows.
STATUSMicrosoft
has confirmed that this is a problem in the Microsoft products that are listed
at the beginning of this article.
REFERENCES For more information on the GetClassInfoEx function, please see the following MSDN reference: For more information on the RegisterClassEx function, please see the following MSDN reference: For a Frame
Window Classes, please see the following MSDN
reference: For additional information, click the article
number below to view the article in the Microsoft Knowledge Base: 167526 FIX: ATL Control May Cause an Access Violation
Modification Type: | Major | Last Reviewed: | 9/2/2005 |
---|
Keywords: | kbtshoot kbprb kbATLWC kbCtrlCreate kbInprocSvr kbpending KB248400 kbAudDeveloper |
---|
|