我用文件读一个PE格式的程序,一碰到0X00就被截断,read之后的返回值正确,但实际上只读一小段
不知道是什么错误。以下是读文件的那部分代码!try{
CStdioFile pFile;
CFileException ex;
pFile.Open(FileName,CFile::modeRead | CFile::typeBinary|CFile::shareDenyNone,&ex);
int nRead = 1;
while(nRead > 0)
{
char pBuf[SIZE*4];
nRead = 0;
nRead = pFile.Read(pBuf,SIZE*4);
Cnt += nRead;
pBuf[nRead] = 0;
TRACE("pBuf's length is %d\n",strlen(pBuf));////////////////
if(nRead > 0)
{
int SendLen=((CNClientApp *)AfxGetApp())->m_socket->SendData((CString)pBuf);
}
}
pFile.Close();
}
catch(...){;}
不知道是什么错误。以下是读文件的那部分代码!try{
CStdioFile pFile;
CFileException ex;
pFile.Open(FileName,CFile::modeRead | CFile::typeBinary|CFile::shareDenyNone,&ex);
int nRead = 1;
while(nRead > 0)
{
char pBuf[SIZE*4];
nRead = 0;
nRead = pFile.Read(pBuf,SIZE*4);
Cnt += nRead;
pBuf[nRead] = 0;
TRACE("pBuf's length is %d\n",strlen(pBuf));////////////////
if(nRead > 0)
{
int SendLen=((CNClientApp *)AfxGetApp())->m_socket->SendData((CString)pBuf);
}
}
pFile.Close();
}
catch(...){;}
你不能使用字符串,因为C-String就是这样的,以'\0'作为结束符,楼主可以复习一下C。
nRead = pFile.Read(pBuf,SIZE*4);
nRead才是你的BUF里面真正有的字节数,详细的看MSDN。