码迷,mamicode.com
首页 > 编程语言 > 详细

静态MFC CSocket CAsyncSocket map_pp.cpp错误

时间:2015-03-11 12:30:29      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

静态MFC,在线程中使用SOCKET,发生错误:

Debug Assertion Failed!
Program:...
File:f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\map_pp.cpp
Line:179

这是MFC的一个BUG,在6.0中就发现,可惜微软到VS2013还是没有修改,估计这个东西微软也要淘汰了,懒得改了,下面是MSDN的解决方法:

When using 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 that 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 be created for 
each thread.The following code shows a function to do 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 be 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 

 

最后这句就是屁话了,我在2013中试了,还是错误,可恶!

静态MFC CSocket CAsyncSocket map_pp.cpp错误

标签:

原文地址:http://www.cnblogs.com/shaoxuejun/p/4329501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!