MFC下载文件出错了,谁来帮帮忙.
jues 2010-07-21 11:53:28 TRY
{
CInternetSession sess ;
// 统一以二进制方式下载
DWORD dwFlag = INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD ;
CHttpFile * pF = (CHttpFile*)sess.OpenURL("http://55.duote.org/sniffpass.exe", 1, dwFlag); ASSERT(pF);
if (!pF)
{AfxThrowInternetException(1);}
// 得到文件大小
CString str ;
pF->QueryInfo (HTTP_QUERY_CONTENT_LENGTH, str) ;
int nFileSize = _ttoi(str) ;
char * p;
p= new char [nFileSize] ;
int i1;
i1=nFileSize;
while (true)
{
// 每次下载8Kb
int n = pF->Read (p, (nFileSize < 8192) ? nFileSize : 8192) ;
if (n <= 0)
break ;
p += n ; nFileSize -= n ;
}
CFile file;
file.Open("d:\\1.exe",CFile::modeCreate|CFile::modeWrite);
file.Write(&p,i1);
file.Close();
delete[] p ;
delete pF ;
}
CATCH_ALL(e) {}
END_CATCH_ALL
//运行后出现如图片上的错误.就算把文件保存到硬盘的那部分代码去掉也不行.
图片地址:http://hi.baidu.com/jues17/album/item/7fdac58afa3b6493fd1f10e3.html