在com中用CSocket类Create出现错误

//debug mfc静态链接
在Com的一个方法中用CSocket类
CSocket  proxySK;
proxySK.create();  //这一句会出错

解决方法:
在函数的开头加上以下代码来在CSocket所在的Thread中初始化CSocket和SOCKET做映射的链表:
#define _afxSockThreadState AfxGetModuleThreadState() 
#define _AFX_SOCK_THREAD_STATE AFX_MODULE_THREAD_STATE 
 
 _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;

据说是一个Bug

原文是这样说的
Hi,

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

Please refer to Q193101 from MSDN
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值