64,649
社区成员
发帖
与我相关
我的任务
分享
m_ServerSocket->Accept(*m_ClientSocket);
m_ClientSocket->m_status=m_ServerSocket->m_status;
m_socketfile=new CSocketFile(m_ClientSocket);
m_archiveIn=new CArchive(m_socketfile,CArchive::load);
m_arvhiveOut=new CArchive(m_socketfile,CArchive::store);
void CNetChatDlg::OnBtnSend()
{
...
UpdateData(TRUE); //从发送编辑框中获得数据
*m_arvhiveOut<<m_Output; //CString m_Output:发送编辑框
m_arvhiveOut->Flush();
...
}
接收时有:void CNetChatDlg::OnRecive()
{
CString strtemp,strrecv,strleft;
UpdateData(TRUE);
*m_archiveIn>>strrecv;
...
}
void CRichEditCat::StreamOutToArchive(CArchive &ar, BOOL bSelection, int nFormat)
{
EDITSTREAM es;
es.pfnCallback = writeStreamCallBack;
es.dwError = 0;
RichEditCookie cookie(ar);
es.dwCookie = (DWORD)&cookie;
if (bSelection)
{
nFormat |= SFF_SELECTION;
int nR=GetWindowTextLength();
SetSel(nR,nR);
}
StreamOut(nFormat, es);
return ;
}
DWORD CALLBACK CRichEditCat::writeStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
RichEditCookie* pCookie = (RichEditCookie*)dwCookie;
CArchive& ar = pCookie->m_ar;
ar.Flush();
DWORD dw = 0;
*pcb = cb;
TRY
{
ar.GetFile()->Write(pbBuff, cb);
}
CATCH(CFileException, e)
{
*pcb = 0;
pCookie->m_dwError = (DWORD)e->m_cause;
dw = 1;
}
AND_CATCH_ALL(e)
{
*pcb = 0;
pCookie->m_dwError = (DWORD)CFileException::generic;
dw = 1;
// DELETE_EXCEPTION(e);
}
END_CATCH_ALL
return dw;
}