Article ID: 179690 - Last Review: December 2, 2003 - Revision: 2.0
FIX: Launching COM Server with Long File Name Returns 0x80080005 This article was previously published under Q179690
A COM local server fails to start, accompanied by the error "Server
Execution Failed" (error number 0x80080005 or -2146959355), if it is
registered in a directory with a long file name that contains a space and a
similar directory name exists at the same level.
If the server is registered with a short file name, this problem does not
occur. This is not a problem for inproc servers. All ATL local servers are
registered with long file names.
This problem is caused by the fact that unquoted long file names containing
spaces are ambiguous to CreateProcess (which is called by CoCreateInstance/
CoGetClassObject). Refer to the CreateProcess documentation for more
information.
This problem can be fixed by overriding the registration functions in the
CComModule derived class and adding code to use the short file name in
registration instead of the long file name. MFC uses short file names for
registration.
Change CExeModule definition in StdAfx.h as follows:
class CExeModule : public CComModule
{
public:
LONG Unlock();
DWORD dwThreadID;
#ifdef _ATL_STATIC_REGISTRY
// Statically linking to Registry component.
HRESULT WINAPI UpdateRegistryFromResourceS(UINT nResID,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries = NULL);
HRESULT WINAPI UpdateRegistryFromResourceS(LPCTSTR lpszRes,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries = NULL);
#else
HRESULT WINAPI UpdateRegistryFromResourceD(LPCTSTR lpszRes,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries = NULL);
HRESULT WINAPI UpdateRegistryFromResourceD(UINT nResID,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries = NULL);
#endif
};
Add the following code to <ProjectName>.cpp after the #includes:
#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#endif
Add the following code to <ProjectName>.cpp before _tWinMain():
#ifdef _ATL_STATIC_REGISTRY
// Statically linking to Registry component.
HRESULT WINAPI CExeModule::UpdateRegistryFromResourceS(UINT nResID,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries)
{
USES_CONVERSION;
CRegObject ro;
TCHAR szModule[_MAX_PATH];
GetModuleFileName(_Module.GetModuleInstance(), szModule,
_MAX_PATH);
TCHAR szModuleShort[_MAX_PATH];
// Convert to short file name.
if (::GetShortPathName(szModule, szModuleShort, _MAX_PATH))
{
lstrcpy(szModule, szModuleShort);
}
LPOLESTR pszModule = T2OLE(szModule);
ro.AddReplacement(OLESTR("Module"), pszModule);
if (NULL != pMapEntries)
{
while (NULL != pMapEntries->szKey)
{
_ASSERTE(NULL != pMapEntries->szData);
ro.AddReplacement(pMapEntries->szKey, pMapEntries->szData);
pMapEntries++;
}
}
LPCOLESTR szType = OLESTR("REGISTRY");
return (bRegister) ? ro.ResourceRegister(pszModule, nResID,
szType) :
ro.ResourceUnregister(pszModule, nResID, szType);
}
HRESULT WINAPI CExeModule::UpdateRegistryFromResourceS(LPCTSTR
lpszRes,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries)
{
USES_CONVERSION;
CRegObject ro;
TCHAR szModule[_MAX_PATH];
GetModuleFileName(_Module.GetModuleInstance(), szModule,
_MAX_PATH);
TCHAR szModuleShort[_MAX_PATH];
// Convert to short file name.
if (::GetShortPathName(szModule, szModuleShort, _MAX_PATH))
{
lstrcpy(szModule, szModuleShort);
}
LPOLESTR pszModule = T2OLE(szModule);
ro.AddReplacement(OLESTR("Module"), pszModule);
if (NULL != pMapEntries)
{
while (NULL != pMapEntries->szKey)
{
_ASSERTE(NULL != pMapEntries->szData);
ro.AddReplacement(pMapEntries->szKey, pMapEntries->szData);
pMapEntries++;
}
}
LPCOLESTR szType = OLESTR("REGISTRY");
LPCOLESTR pszRes = T2COLE(lpszRes);
return (bRegister) ? ro.ResourceRegisterSz(pszModule, pszRes,
szType)
: ro.ResourceUnregisterSz(pszModule, pszRes, szType);
}
#else
ATLAPI MyAtlModuleUpdateRegistryFromResourceD(_ATL_MODULE* pM,
LPCOLESTR lpszRes, BOOL bRegister,
struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg = NULL)
{
USES_CONVERSION;
_ASSERTE(pM != NULL);
HRESULT hRes = S_OK;
CComPtr<IRegistrar> p;
if (pReg != NULL)
p = pReg;
else
{
hRes = CoCreateInstance(CLSID_Registrar, NULL,
CLSCTX_INPROC_SERVER, IID_IRegistrar, (void**)&p);
}
if (SUCCEEDED(hRes))
{
TCHAR szModule[_MAX_PATH];
GetModuleFileName(pM->m_hInst, szModule, _MAX_PATH);
TCHAR szModuleShort[_MAX_PATH];
// Convert to short file name.
if (::GetShortPathName(szModule, szModuleShort, _MAX_PATH))
{
lstrcpy(szModule, szModuleShort);
}
p->AddReplacement(OLESTR("Module"), T2OLE(szModule));
if (NULL != pMapEntries)
{
while (NULL != pMapEntries->szKey)
{
_ASSERTE(NULL != pMapEntries->szData);
p->AddReplacement((LPOLESTR)pMapEntries->szKey,
(LPOLESTR)pMapEntries->szData);
pMapEntries++;
}
}
LPCOLESTR szType = OLESTR("REGISTRY");
GetModuleFileName(pM->m_hInstResource, szModule, _MAX_PATH);
LPOLESTR pszModule = T2OLE(szModule);
if (HIWORD(lpszRes)==0)
{
if (bRegister)
hRes = p->ResourceRegister(pszModule,
((UINT)LOWORD((DWORD)lpszRes)), szType);
else
hRes = p->ResourceUnregister(pszModule,
((UINT)LOWORD((DWORD)lpszRes)), szType);
}
else
{
if (bRegister)
hRes = p->ResourceRegisterSz(pszModule, lpszRes, szType);
else
hRes = p->ResourceUnregisterSz(pszModule, lpszRes,
szType);
}
}
return hRes;
}
HRESULT WINAPI CExeModule::UpdateRegistryFromResourceD(LPCTSTR
lpszRes,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries)
{
USES_CONVERSION;
return MyAtlModuleUpdateRegistryFromResourceD(this,
T2COLE(lpszRes),
bRegister, pMapEntries);
}
HRESULT WINAPI CExeModule::UpdateRegistryFromResourceD(UINT nResID,
BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries)
{
return MyAtlModuleUpdateRegistryFromResourceD(this,
(LPCOLESTR)MAKEINTRESOURCE(nResID), bRegister, pMapEntries);
}
#endif
Save the changes and rebuild all.
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This problem was corrected in Visual C++
version 6.0 for Windows.
Steps to Reproduce Behavior Create two directories, C:\Program Files and C:\Program.
Copy an ATL local server to C:\Program Files.
Register the server.
Attempt to start the server from a client application. Note that the
server does not start and CoCreateInstance returns error 0x80080005.
Copy and register the local server in the directory C:\Program.
Attempt to start the server from a client application. Note that the
server starts. No errors are returned.
NOTE: Surrounding the long file name in the registry with quotation marks
does not solve this problem.
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Mike
Francis, Microsoft Corporation.
APPLIES TO Microsoft ActiveX Template Library 2.1, when used with: Microsoft Visual C++ 5.0 Enterprise Edition Microsoft Visual C++ 5.0 Professional Edition Microsoft Windows NT Server 4.0 Standard Edition Microsoft Windows NT Workstation 4.0 Developer Edition kbbug kbfix kbregistry kbvc600fix kbserver kbatl300fix kblocalsvr KB179690
Provide feedback on this information
Did this information solve your problem?
Was this information relevant?
What can we do to improve this information?
To protect your privacy, do not include contact information in your feedback.
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .