Static MFC CSocket CAsyncSocket Map_pp.cpp Error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.