Help and Support
 

powered byLive Search

BUG: ClassWizard adds the AfxGetStaticModuleState() in an MFC executable program in Visual C++ 6.0

Article ID:231592
Last Review:May 3, 2005
Revision:4.1
This article was previously published under Q231592

SYMPTOMS

When using ClassWizard to add Methods and Properties to an ATL interface in a MFC Application, ClassWizard will add the following line to the top of each function:
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
				
AfxGetStaticModuleState() is used to maintain MFC global state information inside a MFC regular DLL. Using AfxGetStaticModuleState() in an MFC EXE will not change to the correct module state. In addition, it will cause the MFC DLL startup source to be linked into the EXE increasing it's size.


AfxGetAppModuleState() should be used in MFC EXEs.

Back to the top

RESOLUTION

Change the AFX_MANAGE_STATE line to read:
	AFX_MANAGE_STATE(AfxGetAppModuleState())
				
If the same code is used in an EXE and MFC regular DLL, use a #define:
#ifdef _USRDLL
#  define AFXMANAGESTATE AfxGetStaticModuleState()
#else
#  define AFXMANAGESTATE AfxGetAppModuleState()
#endif
				

Back to the top

STATUS

This bug was corrected in Microsoft Visual Studio .NET 2002.

Back to the top

MORE INFORMATION

MFC classes which use global and thread based MFC data need to use a specific MFC module state. As a result, entry points need to switch module states using the AFX_MANAGE_STATE macro to the module state associated with the EXE or DLL.

Entry points that would be affected include callback functions, custom windows procedures, and COM interfaces that are called from inproc servers.

Back to the top

REFERENCES

For more information on MFC Module States, see the MFC technote TN058: MFC Module State Implementation.

Back to the top


APPLIES TO
The ClassWizard, when used with:
  Microsoft Visual C++ 6.0 Enterprise Edition
  Microsoft Visual C++ 6.0 Professional Edition
  Microsoft Visual C++ 6.0 Standard Edition

Back to the top

Keywords: 
kbbug kbfix kbmfc kbarchitecture kbpending KB231592

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.