|
我的做法是Server与Client建立连接,Server端生成一个Custom负责接收Client的数据包。
程序在Server端接收文件,调OnClientRead函数:
pSocket->m_pTCPServer->OnClientRead(pSocket->m_pTCPServer->m_pOwnerWnd, pSocket, recvBuf, recvLen);
这时候报如下错误:
Unhandled exception at 0x00000000 in Server.exe: 0xC0000005: Access violation reading location 0x00000000.
No symbols are loaded for any call stack frame. The source code cannot be displayed.
我以为是OnClientRead函数有问题,于是将OnClientRead函数体注释掉,加了句AfxMessageBox(_T("ok"));但是报同样错误。
TCPServe.h
typedef void (CALLBACK* ONCLIENTCONNECT)(CWnd*, TCPCustom*);
typedef void (CALLBACK* ONCLIENTCLOSE)(CWnd*, TCPCustom*);
typedef void (CALLBACK* ONCLIENTREAD)(CWnd*, TCPCustom*, char* buf, int len);
typedef void (CALLBACK* ONCLIENTERROR)(CWnd*, TCPCustom*, int nErrorCode);
typedef void (CALLBACK* ONSERVERERROR)(CWnd*, TCPServer*, int nErrorCode);
ONCLIENTCONNECT OnClientConnect;
ONCLIENTCLOSE OnClientClose;
ONCLIENTREAD OnClientRead;
ONCLIENTERROR OnClientError;
ONSERVERERROR OnServerError;
函数实在Dlg中实现的。
我以为是这方面的问题,但是很奇怪,我将OnClientRead改成OnClientClose,程序就能继续跑下去。。。很郁闷啊。。。
谢谢各位大哥,给我点指点吧!!
*************************************************************
下面是ServerDlg里的OnClientRead的实现:
void CALLBACK CServerDlg::OnClientClose(CWnd *pWnd, TCPCustom *pTcpCustom)
{
/*CServerDlg* pDlg = (CServerDlg*)pWnd;
int iIndex;
CListBox* pLstConn = (CListBox*)pDlg->GetDlgItem(IDC_LSTCONN);
ASSERT(pLstConn != NULL);
iIndex = pLstConn->FindString(iIndex, pTcpCustom->m_RemoteHost + _T("connecting"));
if(iIndex == LB_ERR)
{
return;
}
pLstConn->DeleteString(iIndex);
*/
}
|
|