BUG: Cannot Open Document from Shell If EXE Has Long File NameLast reviewed: July 24, 1997Article ID: Q148806 |
The information in this article applies to:
SYMPTOMSWhen 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.
CAUSEThe 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.
RESOLUTIONOverride CWinApp::EnableShellOpen() using the sample code below to pass the application's short file name to ::GlobalAddAtom().
STATUSMicrosoft 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |