INFO: Frequently Encountered MFC 3.x to 4.0 Porting IssuesLast reviewed: July 31, 1997Article ID: Q148304 |
The information in this article applies to:
SUMMARYThis article lists some of the most frequently encountered bugs, problems, and other issues that you may experience when attempting to port an application written with MFC 3.x (the MFC included with Visual C++ 2.x) to work with MFC 4.0 (the MFC included with Visual C++ 4.0).
General Issues
OnInitialUpdate executes.3. CWinApp::m_templateList no longer exists. 4. BUG: The CString += operator may break with null strings. 5. BUG: OnWndMsg case for WM_xSCROLL messages breaks when scroll bars are scrolled programmatically.6. BUG: OnInitMenuPopup now deletes the menu temp map before returning. 7. Documented CRuntimeClass::m_pfnConstructObject is now m_pfnCreateObject. 8. BUG: Default dialog-based application doesn't work in Win32s.
CPropertySheet
call to the base class.11. CPropertySheet::DoModal() causes first chance exception in Windows 95. 12. Property Sheets now have a minimum width.
DLLs
in exported functions.15. BUG: DoModal may fail in MFC extension DLLs.
CStatusBar and CToolBar
CFileDialog
MFC ODBC
MFC OLE
STATUSMicrosoft has confirmed that those issues marked with a BUG prefix are bugs in Microsoft Visual C++ version 4.0. We are researching these problems and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
General Issues
Now, as of version 4.0, these four classes are not registered until a window of that type is created. Windows based on a custom WNDCLASS that fill in information from the MFC window classes will likely just fail to show, sending the message that window creation failed. GetLastError returns the value 0x57F (ERROR_WNDCLASS_DOES_NOT_EXIST) to the debug output window if MFC tracing is turned on. From version 4.0 on, you need to provide all of the necessary information when registering custom window classes with RegisterClass or AfxRegisterClass. Do not rely on ::GetClassInfo to retrieve class values for MFC window classes. For additional information, please see MFC Technical Note 1 and the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q140596 TITLE : MFC 4.0 No Longer Pre-Registers Window Classes ARTICLE-ID: Q141752 TITLE : SAMPLE: Limiting 32-bit Applications to a Single Instance This causes problems if there is code in OnSetFocus that refers to CWnd objects that won't be subclassed until the call to the base class OnInitDialog. This problem may also occur in any other handler called as a result of the control getting the focus. For example, radio buttons will generate a BN_CLICKED when they get the focus. For additional information and a workaround, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142274 TITLE : FIX: Assertion Failure When Handling xN_SETFOCUS in CFormView The m_templateList member variable of CWinApp was undocumented in MFC versions prior to 4.0 but was used frequently enough to be called a porting issue. Microsoft recommends that you use the GetFirstDocTemplatePosition() and GetNextDocTemplate() member functions of CWinApp to gain access to the templates for an application. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q106455 TITLE : How to Acquire a List of All CDocument Objects The particular sequence of events that result in this bug is complex. There is a bug in the MFC source code that incorrectly handles the case when a null string is used with the += operator. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142385 TITLE : FIX: Using CString::operator+= May Cause an Access Violation Code was added in MFC 4.0 to pass the full 32 bits of position (when available) on to the OnxScroll handlers because the WM_xSCROLL messages can only pack 16 bits of position information. Unfortunately the code that was added breaks whenever an application programmatically scrolls a scroll bar by sending a WM_xSCROLL message to itself by way of SendMessage. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q147684 TITLE : FIX: Sending WM_xSCROLL Message Causes Invalid ASSERT In MFC version 4.0, calls to AfxLockTempMaps and AfxUnlockTempMaps were added to CWnd::OnInitMenuPopup. When AfxUnlockTempMaps is called, MFC's temporary object map reference count will go to zero causing all temporary MFC objects to be deleted. When the call to OnInitMenuPopup returns, the CMenu pointer passed in to OnInitMenuPopup (which is a temporary pointer) will be invalid. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q141532 TITLE : FIX: OnInitMenuPopup Deletes Temporary Objects m_pfnConstructObject was a documented member variable of CRuntimeClass in MFC versions prior to 4.0, but the name was changed to reflect the change in parameters and return value. The documentation included with Visual C++ 4.0 was not updated to reflect this change and incorrectly references the old function name.
For additional information, please see the Visual C++ Readme file and the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q138971 TITLE : BUG: Default Dialog-Based Application Doesn't Work in Win32s CPropertySheetMuch of the MFC implementation of CPropertySheet has changed to now wrap the Windows Property Sheet common control. There have been some formatting and sizing changes, but more importantly, if code made use of any of the private MFC implementations of CPropertySheet, the code will likely break as most of the undocumented members of that class are no longer there.
For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142170 TITLE : SAMPLE: PRPFONT - How to Set CPropertySheet Fonts During CPropertySheet::OnInitDialog, the property sheet is resized and the four standard buttons (OK, Cancel, Apply, and Help) are hidden at the bottom of modeless property sheets. The proper place to modify the size of the sheet or to customize the four property sheet buttons is in OnInitDialog after the call to the base class. In previous versions of MFC, it was common practice to hide some of the buttons shown with a modal property sheet in OnCreate. These buttons can now be easily removed by modifying styles in the PROPSHEETHEADER structure CPropertySheet::m_psh. For additional information, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q140585 TITLE : PRB: Resizing CPropertySheet in OnInitDialog Does Not Work ARTICLE-ID: Q141039 TITLE : How to Hide the Apply Button in CPropertySheet A first chance exception occurs on Windows 95 because the property page sets required styles in the dialog resource. The operating system needs to handle this, so the message can be ignored. If you surround the DoModal() call with a try/catch(...) block in an effort to handle the exception yourself, you will get a stack fault.
DLLs
For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142243 TITLE : PRB: Cannot Create an MFC Thread During DLL Startup Previously, the USRDLL model required that MFC be statically linked to the DLL. It is now possible to link dynamically to the Mfc40.dll from a Regular DLL (the new term for _USRDLLs). The caveat is that to convert a _USRDLL to be a "Regular DLL using MFC in a Shared Library," you need to make sure that you manage your module state information correctly. The single line:
AFX_MANAGE_STATE(AfxGetStaticModuleState());should be added to the beginning of any function exported from the DLL that operates on MFC objects. The following problems are likely to occur if the module state is not switched appropriately:
ARTICLE-ID: Q140850 TITLE : How to Convert DLLTRACE to Use MFC in Shared Library When MFC 4.0 creates a dialog box, it passes the current instance handle to the ::CreateDialogIndirect Windows API - which creates the dialog instead of the resource handle for the DLL. The template for the dialog was already loaded by MFC from the correct extension DLL. However, Windows will look in the .exe file specified by the instance handle for any extra resources indicated on the template. Windows will not find them if they are in the DLL, and the dialog creation will fail. To work around this problem, the current instance handle should be temporarily switched before any calls to DoModal. Extra resources include such things as the dialog's menu, custom controls, or an icon on the dialog. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q147384 TITLE : FIX: Icons, Bitmaps, & Menus Not Displayed in an AFXDLL Dialog CStatusBar and CToolBarLike CPropertySheet, these MFC classes now wrap the functionality of the Win32 common controls. Any code that relied on or modified the private, undocumented implementation of these classes will likely break when compiled for MFC 4.0. These two common controls support a greater range of common customizations than did the previous default MFC implementation, and they do not require significant overrides of the MFC source for such tasks as constructing palette bars or making resizable toolbars. If needed, the old implementation of these two classes is still present as the COldToolBar and COldStatusBar classes. These implementations can be found in the OLDBARS sample project.
For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q141444 TITLE : DOC: Incorrect Documentation for CToolBar::SetSizes() CFileDialog
GetParent()->GetDlgItem(IDOK)will return a pointer to the Open/Save button on the Explorer dialog. However, this is not recommended because code that relies on the details of the standard Explorer dialog controls will break if the Explorer layout is changed in the future. This default can be changed by removing the OFN_EXPLORER style. For more information, see the following Microsoft Knowledge Base article:
ARTICLE-ID: Q131225 TITLE : PRB: CFileDialog::DoModal() Does Not Display FileOpen Dialog In MFC 4.0, for the file C:\Article.txt:
For additional information, please see the Visual C++ Readme file and the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142203 TITLE : DOCERR: GetFileTitle() & GetFileName() Docs Are Switched MFC ODBC
For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q141303 TITLE : FIX: Dynasets w/ CLongBinary Fields Throws Incorrect Exception MFC OLE
For more information please see MFC Technical Note 59.
REFERENCESYou can find the referenced MFC Technical Notes in the Visual C++ InfoView in the Visual C++ CD-ROM in this directory:
Visual C++ Books MFC 4.0 MFC Technical NotesThe Visual C++ Readme file can be found in the \Msdev\Vcread.wri file or in the Visual C++ InfoView under:
README for Microsoft Visual C++ Version 4.0 Microsoft Foundation Classes (MFC)" |
Additional query words: troubleshoot trouble shoot conversion
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |