Article ID: 148806
Article Last Modified on 11/21/2006
APPLIES TO
- Microsoft Foundation Class Library 4.2, when used with:
- Microsoft Visual C++ 4.0 Standard Edition
- Microsoft Visual C++ 4.1 Subscription
- Microsoft Visual C++ 4.2 Professional Edition
- Microsoft Visual C++ 5.0 Standard Edition
- Microsoft Visual C++ 6.0 Service Pack 5
This article was previously published under Q148806
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 or Windows 98, a dialog box with an error message similar to the following appears:
Closing the message box won't bring up the application's windows, but will leave the executable file open.
On Windows Millennium Edition (Me), the error message is:
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 and Windows 98 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 that this is a bug in the Microsoft products that are listed in the "Applies to" section.
This problem was corrected in Microsoft Visual C++ .NET.
MORE INFORMATION
Steps to reproduce the problem on a computer that is running Windows 95 or Windows 98
- Select a new MFC AppWizard(exe) project to create an MDI application with a long project name.
- At step 3 of the AppWizard select Automation Support.
- Then at step 4 of the AppWizard, choose Advanced and specify a 3 letter file extension.
- Build the application and run it once so the file type is registered by the call to RegisterShellFileTypes in InitInstance.
- Save a file with the selected file extension and double-click to open it from the Windows Explorer.
This can be worked around by overriding CWinApp::EnableShellOpen() and registering the application name atom using the short filename. Following is a sample of what the code should look like:
/* 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")); }
Additional query words: 8.3 filename EnableShellOpen
Keywords: kbbug kbcode kbfix kbnoupdate KB148806