====================================================================== Microsoft(R) Product Support Services Application Note (Text File) SC0622: C++/Microsoft Foundation Class (MFC) Questions & Answers ====================================================================== Revision Date: 10/92 No Disk Included The following information applies to Microsoft C/C++ Compiler version 7.0. -------------------------------------------------------------------- | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY | | ACCOMPANY THIS DOCUMENT (collectively referred to as an | | Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY | | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO | | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A | | PARTICULAR PURPOSE. The user assumes the entire risk as to the | | accuracy and the use of this Application Note. This Application | | Note may be copied and distributed subject to the following | | conditions: 1) All text must be copied without modification and | | all pages must be included; 2) If software is included, all files | | on the disk(s) must be copied without modification [the MS-DOS(R) | | utility DISKCOPY is appropriate for this purpose]; 3) All | | components of this Application Note must be distributed together; | | and 4) This Application Note may not be distributed for profit. | | | | Copyright 1992 Microsoft Corporation. All Rights Reserved. | | Microsoft and MS-DOS are registered trademarks and Windows | | is a trademark of Microsoft Corporation. | -------------------------------------------------------------------- 1. Q. When I link my Microsoft Foundation Class (MFC) application, error L2025, which says that operator NEW and operator DELETE are multiply defined, is displayed. What is causing this error? A. The MFC libraries provide both a debugging version and a release version. The debugging version of the medium model library for Microsoft Windows is called MAFXCWD.LIB, while the release version is MAFXCW.LIB. All debugging libraries end with the letter "D". When you compile applications for MFC, you must define the symbol "_DEBUG" if you are linking with the debugging library. If you do not define "_DEBUG," but you do link with the debugging libraries, you will receive this error. For more information, refer to Q85514 in the article library of the Languages FastTips system, or query on Q85514 in the Microsoft Knowledge Base on CompuServe. 2. Q. Where is the large model Microsoft Foundation Class (MFC) library? A. If you need a library variant that is not provided in the default installation, you can build the library yourself by running the NMAKE command from the MFC\SRC subdirectory. The only MFC library variants that are installed by the default Microsoft C/C++ version 7.0 installation are those needed to build the MFC samples. These are: MAFXCW, MAFXCWD, SAFXCW, SAFXCWD, MAFXCR, MAFXCRD, and LAFXDWD. For more information on creating MFC library variants, please refer to the README.TXT file in the MFC\SRC subdirectory. 3. Q. When I run the DMTEST sample program from the tutorial, I receive incorrect output. The DMTEST program indicates that the "Banipuli" was found even after this record was deleted from the list. A. The DMTEST program contains an error. In the DMTEST.CPP file, line 261 reads: if(pFound->IsEmpty()) This line should read: if(PFound==NULL) For more information, refer to Q84735 in the article library of the Languages FastTips system, or query on Q84735 in the Microsoft Knowledge Base on CompuServe. 4. Q. All my Microsoft Foundation Class (MFC) dialog boxes are displayed with a gray background. How can I produce a default white background? A. There is an undocumented member function of the CDialog class that can be used to set the background color. This function is CDialog::SetCtlBkColor and accepts a single COLORREF value as an argument. Making a call to this function in the OnInitDialog function of your dialog box allows you to set the background to any color you want. If you want to use the default system color in your OnInitDialog function, you first must delete the object m_hBrushCtlBk with the Windows API function DeleteObject, then you must manually set m_hBrushCtlBk to NULL. Finally, make a call to SetCtlBkColor with an argument of -1. For more information, refer to Q85517 in the article library of the Languages FastTips system, or query on Q85517 in the Microsoft Knowledge Base on CompuServe. 5. Q. Can I have far instances of Microsoft Foundation Class (MFC) objects in small or medium memory models? Under Windows, can I force MFC objects to be allocated from the far heap? A. No. MFC only supports objects in the default heap of the ambient memory model for which your program is compiled. Therefore, under small and medium memory models, objects are allocated from the near heap. Under compact and large memory models, objects are allocated from the far heap. 6. Q. If I move my program to the large memory model, can I still run multiple instances of my program? A. It is possible to run multiple instances of large model Windows- based applications if the application has only a single data segment. The MFC library your program is linking with must be recompiled with the compiler switch -Gx specified as an option. To rebuild the large model nondebugging library for Windows, use the following command: NMAKE MODEL=L TARGET=W DEBUG=0 OPT=/Gx For more information on building MFC library variants, please refer to the README.TXT file in the MFC\SRC subdirectory. In addition, you must rebuild your program with the -Gx option and declare any static and/or global class objects with the _NEAR modifier. The -Gx switch instructs the compiler to keep everything that it possibly can in the default data segment. For more information, refer to Q85736 in the article library of the Languages FastTips system, or query on Q85736 in the Microsoft Knowledge Base on CompuServe. 7. Q. I receive the error C2642, which reads "cast to pointer to member must be from related pointer to member." The compiler indicates that this error occurs in a macro between the BEGIN and END MESSAGE MAP statements for my class. What is causing this error? A. This particular compile-time error occurs when the function name and prototype entered as a member function of a CWnd- derived class do not agree with the prototype encoded in the ON_WM message-handler macro. The documentation contains several incorrect prototypes for message-handler functions. Corrections for most of these errors are found in part 7 of the ERRATA2.TXT file in the C700 installation directory. For example, page 796 of the "Class Libraries Reference" documents the function OnVScroll as accepting a CWnd* as its third parameter. In actuality, the third parameter should be a CScrollBar*. All these message-handler functions are correctly prototyped in the file AFXWIN.H. For more information, refer to Q85521 in the article library of the Languages FastTips system, or query on Q85521 in the Microsoft Knowledge Base on CompuServe. 8. Q. Where are the dynamic data exchange (DDE) classes? A. Microsoft Foundation Class (MFC) version 1.0 does not provide classes that wrap any DDE functions. MFC provides considerable support for object linking and embedding (OLE), which supports much of the same level of functionality as DDE, but at a higher level of abstraction. 9. Q. Why does my window disappear immediately after I create it? A. If a window appears on the screen and then immediately disappears, the memory for the window object may have been allocated on the stack and the code that allocated the memory may have gone out of scope. When this occurs, the object's destructor is called. A stack-based object exists only as long as the code that allocates the object remains in scope. The destructor for an object derived from CWnd destroys the window. To avoid this situation, use the NEW operator to allocate memory for a window on the heap. 10. Q. When I try to serialize a floating-point type to a CArchive, I get the error message C2593, which says "operator insert is ambiguous." A. The only native C++ types that CArchive knows how to serialize are the fixed-size types BYTE, WORD, DWORD, and LONG. All integer types can be cast to one of these types for serialization. Floating-point types can be archived using CArchive's member function Write. The syntax to archive a floating-point variable f to an archive ar would read as follows: ar.Write(&f,sizeof(float)) This helps to ensure portability to Windows NT.