2 xiaohuli1 xiaohuli1 于 2013.11.28 14:05 提问

应用程序发生异常unknow software exception(0x80000003)还有degug assertion failed.

TCP大量数据接收时出现“应用程序发生异常unknow software exception(0x80000003),位置为0x7c92120e”还有degug assertion failed.实在找不到错误,各位前辈帮我看看吧

//客户端线程
DWORD WINAPI CTCPSocket::ClientThread(LPVOID lpParameter)
{
CTCPSocket* m_pTCP=(CTCPSocket*)lpParameter;

int nRet;
char buf[500*1024];

timeval tv={0,5000};
fd_set fs;

//不断接收服务器发来数据
while(m_pTCP->m_bAuto)
{
    FD_ZERO(&fs);
    FD_SET(m_pTCP->m_sSocket,&fs);
    if(select(1,&fs,NULL,NULL,&tv)==1)
    {
        nRet=recv(m_pTCP->m_sSocket,buf,500*1024,0);
        if(nRet==SOCKET_ERROR)
        {
            //出错断开(例如服务器关闭)
            m_pTCP->error=WSAGetLastError();
            closesocket(m_pTCP->m_sSocket);
            m_pTCP->m_bAuto=FALSE;
            TRACE("客户端出错断开! \n");

            //回调处理
            if(m_pTCP->m_lpClientStatusProc!=NULL)
            {
                char inf[21];                   
                m_pTCP->m_lpClientStatusProc(inf,21,m_pTCP->m_dwUserData);
            }

            break;
        }

        if(nRet>0)
        {
            //收到新的数据
            TRACE("客户端收到数据%d字节! \n",nRet);

            //数据回调处理
            if(m_pTCP->m_lpClientDataArriveProc!=NULL)
            {

                m_pTCP->m_lpClientDataArriveProc(buf,nRet,m_pTCP->m_dwUserData);

            }

            continue;
        }

        if(nRet==0)
        {
            //服务器正常断开
            TRACE("客户端正常断开! \n");

            //回调处理
            if(m_pTCP->m_lpClientStatusProc!=NULL)
            {
                char inf[21];                               
                m_pTCP->m_lpClientStatusProc(inf,21,m_pTCP->m_dwUserData);

            }
            closesocket(m_pTCP->m_sSocket);
            m_pTCP->m_bAuto=FALSE;

            break;
        }
    }
}

return 0;

}

dlg.cpp中
void CSICKDlg::OnDataArrived(char *data,int length,DWORD userdata)
{
CSICKDlg *pWnd=(CSICKDlg *)userdata;
::SendMessage(pWnd->m_hWnd,WM_DATA_ARRIVED,(WPARAM)data,LPARAM(length));
}

LONG CSICKDlg::OnDataArrivedMsg(char *datamiddlebuf,LPARAM lParam)
{
//处理收到的数据
writethreadInfo writeInfo;
writeInfo.m_writeflag=true;
writeInfo.writebuf=datamiddlebuf;
writeInfo.writedatalength=lParam;
CWinThread *pWrite=AfxBeginThread(Write,&writeInfo,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pWrite->ResumeThread();//创建线程

return 0;

}
UINT CSICKDlg::Write(LPVOID pParam)
{
writethreadInfo* pInfo=(writethreadInfo*)pParam;

int len=pInfo->writedatalength;
    char *write=pInfo->writebuf;
bool flag=pInfo->m_writeflag;
int i;
char binstr[500*1024];
if(flag)
{
    sprintf(binstr,"%02x",write[0]);
    for (i=1;i<len;i++)
    {
        sprintf(binstr,"%s %02x",binstr,(unsigned char)write[i]);

    }
    printf("%s",binstr);
    CString Cwrite=binstr;
    sickFile.Seek(0,CFile::end);
    sickFile.WriteString(Cwrite);
    flag=false;

}

return 0;
}
帮帮我吧,新手实在找不到哪里出错了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!