告假下 MFC写了一个复制函数,为什么复制后缀为.vhd的镜像文件只能复制出一个0字节的空文件

请假下 MFC写了一个复制函数,为什么复制后缀为.vhd的镜像文件只能复制出一个0字节的空文件
本帖最后由 VisualEleven 于 2013-08-29 14:51:54 编辑
RT代码如下
if(filename.IsEmpty()){ 
MessageBox("目标文件为空");
return;
}

if(pathname.IsEmpty())
{MessageBox("存入目标地址错误");
return;
}

readfile=new CFile;
if(readfile==NULL)
exit(1);
readfile->Open(pathname,CFile::modeRead);//open the file

HANDLE m_hand=::CreateFile(fullname,GENERIC_WRITE|GENERIC_WRITE,0,
0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);//create the file
CloseHandle(m_hand);

writefile=new CFile(fullname,CFile::modeWrite);//write the file
if(writefile==NULL)
exit(1);
filelen=readfile->GetLength();//get the length of the file

ldiv_t r;
char temp[1024]; 
ZeroMemory(temp,1024);

r=ldiv(filelen,100);
long pos=r.quot;
long position=pos;
int i=0;


while(position<filelen)
{

readfile->Read(temp,1024);
writefile->Write(temp,1024);
poslen=writefile->GetPosition();
if(poslen>position)
{
position+=pos;
i++;

m_edit.Format("%.0f%%",(float)i);
GetDlgItem(IDC_IDC_EDIT3CPutout)->SetWindowText(m_edit);
GetDlgItem(IDC_IDC_EDIT3CPutout)->UpdateWindow();
m_progress.SetPos(i);
}


readfile->Close();
writefile->Close();
delete readfile;
readfile=NULL;
delete writefile;
writefile=NULL;

------解决方案--------------------
你Debug下调试一下while循环条件满足不?
------解决方案--------------------
r=ldiv(filelen,100);
    long pos=r.quot;
    long position=pos;
这句结果对么 ?
    int i=0;
------解决方案--------------------
WinExec("cmd.exe /c copy d:\\mydir\\a.vhd e:\\a.vhd",SW_HIDE);

------解决方案--------------------
long position=pos; // 这又是为啥?不应该从0开始吗?