FIX: ATL In-Proc Servers Load Twice if Using Short Filename (218475)
The information in this article applies to:
- The Microsoft Active Template Library (ATL) 3.0, when used with:
- Microsoft Visual C++, 32-bit Professional Edition 6.0
This article was previously published under Q218475 SYMPTOMS
Active Template Library (ATL) uses the DECLARE_REGISTRY_RESOURCEID macro and registers the COM object with the short filename when registering an in-proc COM object. This causes such problems as not hitting breakpoints or seeing two copies of global data.
CAUSE
Windows NT's LoadLibrary incorrectly loads a DLL twice if a long and short filename are used. In an ATL DLL COM server where you are also implicitly linked to the DLL, COM uses the short filename where the Windows NT loader uses the long filename when loading the DLL.
RESOLUTION
In the atlbase.h file, override the following functions: AtlModuleUpdateRegistryFromResourceD (for non-static builds) and both versions of CComModule::UpdateRegistryFromResourceS (for static builds). In addition, replace this code sample:
// Convert to short path to work around bug in Windows NT 4.0's CreateProcess
TCHAR szModuleShort[_MAX_PATH];
GetShortPathName(szModule, szModuleShort, _MAX_PATH);
LPOLESTR pszModule = T2OLE(szModuleShort);
with the following:
LPOLESTR pszModule;
if ((pM->m_hInst == NULL) || (pM->m_hInst == GetModuleHandle(NULL))) // register as EXE
{
// Convert to short path to work around bug in NT4's CreateProcess
TCHAR szModuleShort[_MAX_PATH];
int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH);
if (cbShortName == _MAX_PATH)
return E_OUTOFMEMORY;
pszModule = (cbShortName == 0 || cbShortName ==
ERROR_INVALID_PARAMETER) ? T2OLE(szModule) : T2OLE(szModuleShort);
}
else
pszModule = T2OLE(szModule);
In the new code, the DLL servers are registered using the long filename whereas the .exe file servers are registered using the short file name.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Visual Studio 6.0 Service Pack 3.
For more information about Visual Studio 6.0 Service Packs, please see the following articles in the Microsoft Knowledge Base: 194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why 194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed
REFERENCES193513 BUG: Breakpoints Not Hit in ATL MMC Snap-In
179690 FIX: Launching COM Server with Long File Name Returns 0x80080005
Modification Type: | Major | Last Reviewed: | 10/17/2003 |
---|
Keywords: | kbBug kbDLL kbfix kbRegistry kbVS600sp3fix KB218475 |
---|
|