// DataSocket.cpp : 实现文件
//#include "stdafx.h"
#include "Chat.h"
#include "DataSocket.h"
#include ".\datasocket.h"
#include "ChatDlg.h"
#include "Messg.h"
// CDataSocketCDataSocket::CDataSocket()
{
m_aSessionIn=NULL;
m_aSessionOut=NULL;
m_sfSocketFile=NULL;
}CDataSocket::~CDataSocket()
{
if(m_aSessionIn)
delete m_aSessionIn;
if(m_aSessionOut)
delete m_aSessionOut;
if(m_sfSocketFile)
delete m_sfSocketFile;
}
void CDataSocket::CloseSocket()
{
if(m_aSessionIn)
{
delete m_aSessionIn;
m_aSessionIn=NULL;
}
if(m_aSessionOut)
{
delete m_aSessionOut;
m_aSessionOut=NULL;
}
if(m_sfSocketFile)
{
delete m_sfSocketFile;
m_sfSocketFile=NULL;
}
Close();
}
void CDataSocket::Init (CChatDlg* pDlg)
{
m_sfSocketFile=new CSocketFile(this);
m_aSessionIn=new CArchive(m_sfSocketFile,CArchive::load);
m_aSessionOut=new CArchive(m_sfSocketFile,CArchive::store);
m_pDlg=pDlg;
}
BOOL CDataSocket::SendMessage(CMessg& msg)
{
if(m_aSessionOut!=NULL)
{
msg.Serialize(*m_aSessionOut);
m_aSessionOut->Flush();
return TRUE;
}
else
return FALSE;
}
CString CDataSocket::GetLocalHostName()
{
char szHostName[256];
if(gethostname(szHostName,sizeof(szHostName))!=0)
return CString("");
else
return CString(szHostName);
}
CString CDataSocket::GetIPAddress()
{
hostent* lpHostEnt;
char szHostName[256];
LPSTR lpAddr;
struct in_addr inAddr;
if(gethostname(szHostName,sizeof(szHostName))!=0)
return CString("");
lpHostEnt=gethostbyname(szHostName);
if(lpHostEnt==NULL)
return CString("");
lpAddr=lpHostEnt->h_addr_list[0];
if(lpAddr==NULL)
return CString("");
memmove(&inAddr,lpAddr,4);
return CString(inet_ntoa(inAddr));
}
// CDataSocket 成员函数void CDataSocket::OnClose(int nErrorCode)
{
m_pDlg->OnSocketClose(this);
return;
CSocket::OnClose(nErrorCode);
}void CDataSocket::OnReceive(int nErrorCode)
{
static CMessg msg;
CString buffer;
do
{
try
{
msg.Serialize(*m_aSessionIn);
buffer+=msg.m_strText;
}
catch(CFileException e) //这里提示有问题,在下面:
{
m_pDlg->OnSocketClose(this);
}
}while(!m_aSessionIn->IsBufferEmpty ());
msg.m_strText=buffer;
m_pDlg->OnSocketReceive(this,msg);
}
出错提示:
d:\My Documents\Visual Studio Projects\Chat\DataSocket.cpp(112) : error C2316: “CFileException” : 无法作为析构函数捕获,或者复制构造函数不可访问,或同时出现这两种情况谢谢大家帮忙!
//#include "stdafx.h"
#include "Chat.h"
#include "DataSocket.h"
#include ".\datasocket.h"
#include "ChatDlg.h"
#include "Messg.h"
// CDataSocketCDataSocket::CDataSocket()
{
m_aSessionIn=NULL;
m_aSessionOut=NULL;
m_sfSocketFile=NULL;
}CDataSocket::~CDataSocket()
{
if(m_aSessionIn)
delete m_aSessionIn;
if(m_aSessionOut)
delete m_aSessionOut;
if(m_sfSocketFile)
delete m_sfSocketFile;
}
void CDataSocket::CloseSocket()
{
if(m_aSessionIn)
{
delete m_aSessionIn;
m_aSessionIn=NULL;
}
if(m_aSessionOut)
{
delete m_aSessionOut;
m_aSessionOut=NULL;
}
if(m_sfSocketFile)
{
delete m_sfSocketFile;
m_sfSocketFile=NULL;
}
Close();
}
void CDataSocket::Init (CChatDlg* pDlg)
{
m_sfSocketFile=new CSocketFile(this);
m_aSessionIn=new CArchive(m_sfSocketFile,CArchive::load);
m_aSessionOut=new CArchive(m_sfSocketFile,CArchive::store);
m_pDlg=pDlg;
}
BOOL CDataSocket::SendMessage(CMessg& msg)
{
if(m_aSessionOut!=NULL)
{
msg.Serialize(*m_aSessionOut);
m_aSessionOut->Flush();
return TRUE;
}
else
return FALSE;
}
CString CDataSocket::GetLocalHostName()
{
char szHostName[256];
if(gethostname(szHostName,sizeof(szHostName))!=0)
return CString("");
else
return CString(szHostName);
}
CString CDataSocket::GetIPAddress()
{
hostent* lpHostEnt;
char szHostName[256];
LPSTR lpAddr;
struct in_addr inAddr;
if(gethostname(szHostName,sizeof(szHostName))!=0)
return CString("");
lpHostEnt=gethostbyname(szHostName);
if(lpHostEnt==NULL)
return CString("");
lpAddr=lpHostEnt->h_addr_list[0];
if(lpAddr==NULL)
return CString("");
memmove(&inAddr,lpAddr,4);
return CString(inet_ntoa(inAddr));
}
// CDataSocket 成员函数void CDataSocket::OnClose(int nErrorCode)
{
m_pDlg->OnSocketClose(this);
return;
CSocket::OnClose(nErrorCode);
}void CDataSocket::OnReceive(int nErrorCode)
{
static CMessg msg;
CString buffer;
do
{
try
{
msg.Serialize(*m_aSessionIn);
buffer+=msg.m_strText;
}
catch(CFileException e) //这里提示有问题,在下面:
{
m_pDlg->OnSocketClose(this);
}
}while(!m_aSessionIn->IsBufferEmpty ());
msg.m_strText=buffer;
m_pDlg->OnSocketReceive(this,msg);
}
出错提示:
d:\My Documents\Visual Studio Projects\Chat\DataSocket.cpp(112) : error C2316: “CFileException” : 无法作为析构函数捕获,或者复制构造函数不可访问,或同时出现这两种情况谢谢大家帮忙!
{
msg.Serialize(*m_aSessionIn);
buffer+=msg.m_strText;
}
catch(CFileException e) //这里提示有问题,在下面:
{
m_pDlg-> OnSocketClose(this);
}
你要捕获什么异常呢?