afx.h stdafx.h and some thoughts on the VS project

1.
The header file contains some definitions and settings, provides the most basic support for MFC, organizes various loose things, and provides convenience for the subsequent establishment of the MFC class library. One of the simplest MFC only needs afxwin.h, and afxwin.h starts with #include "afx.h"
Specifically, the content of afx.h is as follows:
1. Compile option settings, including the default values ​​of warning, etc.
2. Some header files: afxver_h, C related header files, some win32 libraries, including MFC library
3. Some basic class declarations, constants, global variables, functions, and some typedefs, type redefinitions (compatibility, etc.), and Diagnostic function support, . Also includes some macros that are convenient for diagnosis (due to the rigor of MFC, afx.h provides a large number of macros that are convenient for other MFC header files, etc.)

Second, the difference between afx.h and stdafx.h

stdafx.h is a precompiled header file:

#include <afxwin.h> 
#include <afxext.h> 
#include <afxdisp.h> 
#include <afxdtctl.h> 
#include <afxcmn.h> 


stdafx.cpp 中的内容: 
#include "stdafx.h" 

Creating an MFC project will automatically generate the stdafx.h precompiled header file and stdafx.cpp

There is no function library in stdafx.h, but some environment parameters are defined, so that the compiled program can run in a 32-bit operating system environment.
Both Windows and MFC include files are very large, and even with a quick handler, it can take quite a while to compile the program to do the job. Since every .CPP file contains the same include files, it would be silly to process these files repeatedly for every .CPP file.
To avoid this waste, AppWizard and VisualC++ compiler work together, as shown below:
◎AppWizard creates a file stdafx.h, which contains all the MFCinclude files required by the current project file. And this file can vary with the option selected.
◎AppWizard then builds stdafx.cpp. This file is usually the same.
◎Then AppWizard builds the project file, so the first compiled file is stdafx.cpp.
◎When VisualC++ compiles the stdafx.cpp file, it saves the result in a file named stdafx.pch. (The extension pch means precompiled header file.)
◎When VisualC++ compiles each subsequent .cpp file, it reads and uses the .pch file it just generated. VisualC++ no longer analyzes Windowsinclude files unless you edit stdafx.cpp or stdafx.h again.

It's a neat technique, don't you think? (Also, Microsoft wasn't the first to adopt this technology, Borland was.) You must follow these rules along the way:

◎Any .cpp file you write must include stdafx.h first.
◎If you have most of the .cpp files in the project file and need .h files, add them to stdafx.h (back) by the way, and then precompile stdafx.cpp.
◎Because the .pch file has a lot of symbol information, it is the largest file in your project file.
If you have limited disk space, you may want to delete the .pch file in the project file that you never use. They are not needed when the program is executed, and are automatically recreated as the project file is recreated.

Creating a project can use precompiled header technology, which greatly improves the compilation speed~

3. Some typedefs in afx.h
typedef int BOOL C99 new standard

  • The initial C standard does not have bool type, use this method to support bool type
  • 32-bit machines are most efficient with 4-byte alignment
  • Enhanced function logic readability
  • 0 is FALSE, 1 is TRUE and bool 0 is false, non-0 is true

Fourth, create a filter in VS

When using VS2010 to develop a project, sometimes there are too many source files, and you want to classify and manage them by function. At this time, you can use "filter".

Adding a filter is as simple as right-clicking on the project, selecting Add | New Filter, and naming it. Then add files to the filter. After creating the filter, pay attention to the "*.filters" file in the project directory must not be deleted, because this file is used to record the filter.

Creating filters can improve efficiency, virtual visualization of classified resources (virtual directory of project files)

You can modify the filter configuration through the *.filters project file, modify /CiInclude to include header files, and /ClCompile to modify .cpp files, etc.

Five, VS project generated file analysis

sln is the configuration of the solution, mainly to manage multiple vcxproj in this solution.
vcxproj is the configuration file of the project. It manages the details of the project, such as included files, reference libraries, etc.
Generally , there is no sln. You can also directly open vcxproj or regenerate it. There are multiple projects in sln
sln, when you remove a project, sln will change, sln is not too important

...the first time I entered the rivers and lakes, the road is at my feet

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324871480&siteId=291194637