Static MFC, using the socket in the thread, error occurred:
Debug Assertion failed!
Program: ...
File:f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\map_pp.cpp
line:179
This is a bug in MFC, in 6.0 found, unfortunately, Microsoft to VS2013 still did not modify, estimate this thing Microsoft also want to eliminate, lazy change, the following is the solution of MSDN:
When using the MFC sockets in secondary threads in a statically linked MFC
Visual C + + 6.0 application, an unhandled exception occurs. The reason for
The unhandled exception is this an object of type cmapptrtoptr pointer,
pointed to by M_pmapsockethandle, is never created.
To resolve it the handle maps used by the sockets need to being created for
Each thread. The following code shows a function to does this:
void Socketthreadinit ()
{
#ifndef _afxdll
#define _afx_sock_thread_state Afx_module_thread_state
#define _afxsockthreadstate afxgetmodulethreadstate ()
_afx_sock_thread_state* pState = _afxsockthreadstate;
if (Pstate->m_pmapsockethandle = = NULL)
Pstate->m_pmapsockethandle = new CMapPtrToPtr;
if (pstate->m_pmapdeadsockets = = NULL)
Pstate->m_pmapdeadsockets = new CMapPtrToPtr;
if (pstate->m_plistsocketnotifications = = NULL)
Pstate->m_plistsocketnotifications = new CPtrList;
#endif
}
This function should is called once in each secondary thread before the
First socket is created in the new thread.
Imp:this bug was corrected in Visual Studio 6.0 Service Pack 3
The last sentence is fart words, I tried in 2013, or wrong, hateful!
Static MFC CSocket CAsyncSocket Map_pp.cpp Error