The information in this article applies to:
SUMMARY
The Microsoft Foundation Classes (MFC) samples provide an excellent
starting point for learning basic, intermediate, and advanced MFC
application programming techniques. Although these samples are easily built
in the development environment with which they are shipped, the general
requirements for building MFC applications are not clearly outlined in the
documentation of the products listed above. This article elaborates on the
process.
MORE INFORMATION
When building MFC applications, make sure #include "stdafx.h" is the first
line of the .cpp file. This file includes most of the classes needed for
MFC Windows-based applications. It also includes AFX.H, which contains
declarations for CObject and other basic classes, data types, and macros.
The AFX.H file does not include the additional Windows and Windows NT
specific classes needed for these types of applications, and is often used
instead of AFXWIN.H for MS-DOS programs.
The following describes the naming conventions of the Win32 MFC libraries
included with Visual C++ 32-bit Edition, versions 4.0:
Although the libraries necessary for building the sample programs are
provided, additional variants must be built if required. This process is
explained in the README.TXT file contained by default in the ...\MFC\SRC
directory.
In addition to the library variants above, Visual C++ contains DLL versions of the MFC classes. These are explained in MFC Technote #33. The following command lines build a medium model 16-bit Windows-based application: Debug: cl /c /GA /GEs /Zp /Od /Zi /AM /D_DEBUG hello.cppRelease: cl /c /GA /GEs /Zp /AM hello.cppThe /NOD link option is recommended to prevent accidentally linking with an MS-DOS version of the C run-time library. The following command lines build a Win32-based application: Debug: cl /c /Od /Zi /D_DEBUG /D_X86_ /D_WINDOWS hello.cppRelease: cl /c /D_X86_ /D_WINDOWS hello.cppIn Visual C++ 4.0, _X86_ has been replace by _M_IX86. More importantly, with MFC version 3.0 and later (Visual C++ 2.0 and later), it is no longer necessary to manually specify the version of the MFC library. Instead, the included MFC header files automatically determine the correct version of the MFC library. For more information, see the "Library Versions" topic of "Programming with MFC: Encyclopedia" in the Visual C++ 4.0 Books Online. The MFC libraries should be specified as the first library on your link line for all applications. Notice that if you link with a debug variant of an MFC library ("D" suffix), you must also define _DEBUG during compilation. For more information on this subject, query on the following words in the Microsoft Knowledge Base: mfc and safxcrd and _debug and librariesAlthough the compile and link lines must be modified appropriately for MS- DOS-based or Win32-based console applications, the same guidelines apply. The Resource Compiler can be used with console applications, but doesn't have to be. Also, _CONSOLE must be defined instead of _WINDOWS (This is not necessary with Visual C++ 4.0.) With MS-DOS programs, the Resource Compiler is not used, and _DOS must be defined instead of _WINDOWS. In the Windows example above, the compiler option /GA defines the constant _WINDOWS; however, if other compiler options are used, _WINDOWS may need to be defined in your code. (Including the file AFXWIN.H in your application will cause _WINDOWS to be defined.) Additional query words:
Keywords : kbnokeyword kbMFC kbVC100 kbVC150 kbVC200 kbVC400 kbGrpMFCATL |
Last Reviewed: November 25, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |