//复制文件的函数
BOOL CommonCopyFile(CString SourceFileName, CString DestFileName)
{
CFile sourceFile ;
CFile destFile ;
CFileException ex;
if (!sourceFile.Open((LPCTSTR)SourceFileName,CFile::modeRead | CFile::shareDenyWrite, &ex))
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
CString ErrorMsg = "打开文件:" ;
ErrorMsg += SourceFileName ;
ErrorMsg += "失败。\n错误信息为:\n" ;
ErrorMsg += szError ;
AfxMessageBox(ErrorMsg);
return FALSE ;
}
else
{
if (!destFile.Open((LPCTSTR)DestFileName, CFile::modeWrite | CFile::shareExclusive | CFile::modeCreate, &ex))
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
CString ErrorMsg = "创建文件:" ;
ErrorMsg += DestFileName ;
ErrorMsg += "失败。\n错误信息为:\n" ;
ErrorMsg += szError ;
AfxMessageBox(ErrorMsg);
sourceFile.Close();
return FALSE ;
}
BYTE buffer[4096];
DWORD dwRead;
do
{
dwRead = sourceFile.Read(buffer, 4096);
destFile.Write(buffer, dwRead);
}
while (dwRead > 0);
destFile.Close();
sourceFile.Close();
}
return TRUE ;
}