BUG: Cannot Open Document from Shell If EXE Has Long File Name

Last reviewed: July 24, 1997
Article ID: Q148806
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2, 5.0

         on the following platform:
         - Windows 95
    

SYMPTOMS

When you try to open a document whose extension is associated with an MFC application that has a long file name on Windows 95, a dialog box with an error message similar to the following appears:

   Cannot find the file 'filename' (or one of its components). Make sure
   the path and filename are correct and that all required libraries are
   available.

Closing the message box won't bring up the application's windows, but will leave the executable file open.

NOTE: This problem does not happen on Windows NT.

CAUSE

The MFC function CWinApp::RegisterShellFileTypes() writes the application's 8.3 file name to the registry. However, CWinApp::EnableShellOpen() calls ::GlobalAddAtom() with the application's long file name. Windows 95 cannot handle this situation.

RESOLUTION

Override CWinApp::EnableShellOpen() using the sample code below to pass the application's short file name to ::GlobalAddAtom().

STATUS

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

MORE INFORMATION

Sample Code

   /* Compile options needed: Default MFC applications.
   */

   void CLongFileNameApp::EnableShellOpen()
   {
       ASSERT(m_atomApp == NULL && m_atomSystemTopic == NULL); // do once

       CString strShortName;
       TCHAR szLongPathName[_MAX_PATH];
       ::GetModuleFileName(m_hInstance, szLongPathName, _MAX_PATH);
       if (::GetShortPathName(szLongPathName,
           strShortName.GetBuffer(_MAX_PATH), _MAX_PATH) == 0)
       {
           // Rare failure case (especially on not-so-modern file systems)
           strShortName = szLongPathName;
       }
       strShortName.ReleaseBuffer();
       int nPos = strShortName.ReverseFind('\\');
       if (nPos != -1)
           strShortName = strShortName.Right(strShortName.GetLength()-
                                         nPos-1);
       nPos = strShortName.ReverseFind('.');
       if (nPos != -1)
           strShortName = strShortName.Left(nPos);
       m_atomApp = ::GlobalAddAtom(strShortName);
       m_atomSystemTopic = ::GlobalAddAtom(_T("system"));
   }
 

	
	


Keywords : kbprg MfcMisc vcbuglist400 vcbuglist500 kbbuglist
Technology : kbMfc
Version : 4.0 4.1 4.2
Platform : WINDOWS
Issue type : kbbug


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: July 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.