MFCMultiple States are defined. Here we will introduce the module status, Process status, and thread status. These statuses can be combined, for exampleMFCThe handle ing is locally valid for the module and thread. It belongs to the module.-A part of the thread status.
Module status
The meaning of the module here is: an executable program or an applicationMFC DLLOfDLLFor exampleOLEA widget is a module.
Each module of an application has a status. The module status includes the following information:WindowsInstance handle, pointing to the currentCWinAppOrCWinThreadObject Pointer,OLEModule reference count,WindowsObjects and correspondingMFCIng between objects. Only the application status of a single module9-1.
M_pModuleStatePointer is a member variable of the thread object, pointing to the current module status information (AFX_MODULE_STATEStructure Variable ). When the program runs into a specific module, you must ensure that the current module status is valid-the module status of this specific module. Therefore, each thread object has a pointer pointing to a valid module state. Every time it enters a module, it must point to the status of a valid module, this is very important for maintaining the global state of the application and the integrity of the state of each module. To achieve this, all entry points of each module are responsible for switching the module status. The module entry points include:DLLOutput Functions;OLE/COMWindow Process.
Process and dynamic link in the presentation windowMFC DLLRulesDLLThe statementAFX_MANAGE_STATE (AfxGetStaticModuleState ())It is used to switch the module status at the entry point. The implementation mechanism will be later9.4.1Section.
Status switches between multiple modules9-2.
Figure9-2Medium,M_pModuleStateAlways point to the status of the current module.
Data Structure of the module, process, and thread status
MFC