Microsoft KB Archive/316312

= FIX: Mfc70.lib Does Not Export AfxGetModuleThreadState =

Article ID: 316312

Article Last Modified on 4/11/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q316312



SYMPTOMS
When you develop a Microsoft Foundation Class (MFC) application in Microsoft Visual Studio .NET, you can use the AfxGetModuleThreadState function in debug builds. However, in release builds, the link process fails with the message that AfxGetModuleThreadState is an unresolved external call.



CAUSE
In the retail version of Visual Studio .NET, Mfc70.lib does not export the undocumented AfxGetModuleThreadState function. In the debug version of Visual Studio .NET, Mfc70d.lib exports the AfxGetModuleThreadState function.



RESOLUTION
Undocumented functions such as AfxGetModuleThreadState are not guaranteed to be compatible across versions. These functions are designed for use exclusively in internal MFC library code. Application developers must assume the risk of using undocumented calls.

However, the AfxGetModuleThreadState function is useful to application developers who must use the common ToolTip control. In Visual C++ 6.0, this function is used commonly in the following manner: CToolTipCtrl* pToolTipCtrl = AfxGetModuleThreadState->m_pToolTip; For Visual C++ .NET, this approach fails in a release build. Alternatively, you can use the following method: CToolTipCtrl* pToolTipCtrl = AfxGetModuleState->m_thread.GetDataNA->m_pToolTip; You can use this method to retrieve other thread-specific data elements, also. For example, if a socket window is associated with a thread, you can retrieve the socket window handle this manner through the m_hSocketWindow variable.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).



MORE INFORMATION
Because MFC uses a common ToolTip control, some applications access the MFC ToolTip control through the thread-specific storage in MFC. The ToolTip control, which is stored in the thread data structure, is shared so that each application does not have to have a separate ToolTip control. As a result of this access method, you can call GetToolTips in the CToolBarCtrl class and receive a null return value.

