BUG: Launching COM Server with Long File Name Returns 0x80080005

Last reviewed: January 22, 1998
Article ID: Q179690
The information in this article applies to:
  • The Microsoft Active Template Library (ATL) 2.1 included with: - Microsoft Visual C++, 32-bit Editions, version 5.0
  • Microsoft Windows NT 4.0

SYMPTOMS

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.

CAUSE

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.

RESOLUTION

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.

  1. 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
          };
    
    

  2. Add the following code to <ProjectName>.cpp after the #includes:

          #ifdef _ATL_STATIC_REGISTRY
          #include <statreg.h>
          #endif
    

  3. 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
    
    

  4. Save the changes and rebuild all.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create two directories, C:\Program Files and C:\Program.

  2. Copy an ATL local server to C:\Program Files.

  3. Register the server.

  4. Attempt to start the server from a client application. Note that the server does not start and CoCreateInstance returns error 0x80080005.

  5. Copy and register the local server in the directory C:\Program.

  6. 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.


Additional query words: 80080005 -2146959355 LFN atl registration server
execution failed
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Mike
Francis, Microsoft Corporation
Keywords : AtlServer vcbuglist500 kbcode
Technology : ole
Version : WINDOWS:2.1; WINNT:4.0
Platform : WINDOWS winnt
Issue type : kbbug
Solution Type : kbpending


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 22, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.