CFileException异常怎么调试???????????

cdm2179 2010-08-06 10:43:40
为什么CFile.open成功,为什么还会有CFileException异常?怎么调试呢?

SendFiles.exe 中的 0x7c812afb 处未处理的异常: Microsoft C++ 异常: 内存位置 0x01e2fbf4 处的 CFileException。


for(int i = 0; i <= pDlg->m_strFileName.GetUpperBound(); i++)
{
UINT uiLength = 0;// 文件数据大小
int iBufSize = 1024 * 5; // 发送缓冲大小
int iSize = 0; // 实际发送缓冲大小
int iNumByte = 0; // 一次send实际发送的数据大小
UINT uiTotal = 0; // 目前已发送的数据大小
BYTE *pSendBuf = new BYTE[iBufSize]; // 发送数据信息
CFile file;

CString str = pDlg->m_strDir + pDlg->m_strFileName.GetAt(i);
CFileException ex;
if( !file.Open(pDlg->m_strDir + pDlg->m_strFileName.GetAt(i), CFile::modeRead) )
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
AfxMessageBox("打开文件出错!");
socketSvr.Close();
socketClt.Close();
return 0;
}
uiLength = (UINT)file.GetLength();
socketClt.Send((void *)&uiLength, 4);
while(uiTotal < (UINT)uiLength)
{
// 根据剩余数据大小,决定iSize
iSize = (int)(uiLength - uiTotal) > iBufSize ? iBufSize : (int)(uiLength - uiTotal);
iSize=file.Read((void *)pSendBuf, iSize);//得到读取的字节数
int iCount=0;
while(iCount<iSize)
{
iNumByte = socketClt.Send((void *)pSendBuf, iSize-iCount);
if(iNumByte == SOCKET_ERROR)
{
AfxMessageBox("发送错误!");
socketSvr.Close();
socketClt.Close();
file.Close();
delete[] pSendBuf;
return 0;
}
iCount+=iNumByte;
if(iCount<iSize)
{
pSendBuf += iCount;
}
}
uiTotal += iCount;
}
char szEnd[3]; // 接收OK确认信息
int nRecv = socketClt.Receive((void *)szEnd, 3);
szEnd[nRecv] = '\0';
if(::lstrcmp(szEnd, "OK") != 0)
{
AfxMessageBox("发送文件失败!");
socketSvr.Close();
socketClt.Close();
file.Close();
delete[] pSendBuf;
return 0;
}
file.Close();
delete[] pSendBuf;
}
char szEnd[3]; // 接收OK确认信息
int nRecv = socketClt.Receive((void *)szEnd, 3);
szEnd[nRecv] = '\0';
if(::lstrcmp(szEnd, "OK") != 0)
{
AfxMessageBox("发送文件夹失败!");
socketSvr.Close();
socketClt.Close();
return 0;
}


...全文
287 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2010-08-06
  • 打赏
  • 举报
回复
一般这样写
try
{
// 文件操作相关
}
catch(CFileException* e)
{
e->ReportError();
e->Delete();
}
catch(CException* e)
{
...
}
cdm2179 2010-08-06
  • 打赏
  • 举报
回复
这异常是有时出现,有时没出现的,我晕
hslinux 2010-08-06
  • 打赏
  • 举报
回复
给你个思路吧,先把文件读取部分抽取出来调试下先,文件读取部分没问题了再把网络发送部分加上去。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧