16,471
社区成员
发帖
与我相关
我的任务
分享
void CIExample0042aDlg::OnButton1() //打开文件按钮
{
LPCTSTR lpszPathName;
CString m_CyrrentFileName;
m_CyrrentFileName=lpszPathName;
CFile binfile;
binfile.Open(lpszPathName,CFile::modeRead|CFile::shareExclusive);
ReadBin(&binfile);
binfile.Close();
StringBin();
}
BOOL CIExample0042aDlg::ReadBin(CFile *pBinFile)
{
m_nSize =pBinFile->GetLength();
if(m_nSize==0)
{
MessageBox("Binary file has 0 size !");
return FALSE;
}
if(m_pBuffer)
delete []m_pBuffer;
m_pBuffer=new BYTE[m_nSize];
if(m_pBuffer==0)
{
MessageBox("Not enough memory !");
return FALSE;
}
pBinFile->ReadHuge(m_pBuffer,m_nSize);
return TRUE;
}
BOOL CIExample0042aDlg::StringBin()
{
BYTE *pTmp=m_pBuffer;
CString tmp;
CString prompt;
char m_HexStrArray;
BYTE comment[40];
m_HexStrArray.RemoveAll(); //编译时提示没有remove all()函数
int FullRows=m_nSize/16;
int PartRow=m_nSize%16;
for(int rr=0;rr < FullRows ; rr++)
{
tmp.Format("%05X:", 8*rr);//"10000:" 8Words
prompt+=tmp;
for(int col = 0;col < 16; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else
comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
if(PartRow!=0)
{
tmp.Format("%05X:", 8*rr);
prompt+=tmp;
for(int col = 0;col < PartRow; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else
comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
while(col<16)
{
prompt+=" ";//3
col++;
}
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt); //编译时提示没有add()函数
prompt.Empty();
}
return TRUE;
}
提示有好多错误
急死我了int FullRows=m_nSize/16;
int PartRow=m_nSize%16;
for(int rr=0;rr < FullRows ; rr++)
{
tmp.Format("%05X:", 8*rr);//"10000:" 8Words
prompt+=tmp;
for(int col = 0;col < 16; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else
comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
if(PartRow!=0)
{
tmp.Format("%05X:", 8*rr);
prompt+=tmp;
for(int col = 0;col < PartRow; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else
comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
while(col<16)
{
prompt+=" ";//3
col++;
}
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt); //编译时提示没有add()函数
prompt.Empty();
}
return TRUE;
BOOL CShowHexDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
// do not call base
// if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE;
// TODO: Add your specialized creation code here
m_CyrrentFileName=lpszPathName;
CFile binfile;
binfile.Open(lpszPathName,CFile::modeRead|CFile::shareExclusive);
ReadBin(&binfile);
binfile.Close();
// show
StringBin();
//
return TRUE;
}
//Read Binary File into Buffer
BOOL CShowHexDoc::ReadBin(CFile *pBinFile)
{
m_nSize =pBinFile->GetLength();
if(m_nSize==0)
{
AfxMessageBox("Binary file has 0 size !",MB_ICONSTOP);
return FALSE;
}
//
if(m_pBuffer) delete []m_pBuffer;
//
m_pBuffer=new BYTE[m_nSize];
if(m_pBuffer==0)
{
AfxMessageBox("Not enough memory !",MB_ICONSTOP);
return FALSE;
}
pBinFile->ReadHuge(m_pBuffer,m_nSize); //
//
return TRUE;
}
// Fill a string array in hex format
BOOL CShowHexDoc::StringBin()
{
BYTE *pTmp=m_pBuffer;
CString tmp;
CString prompt;
BYTE comment[40];
// if is there an old
m_HexStrArray.RemoveAll();
//
int FullRows=m_nSize/16;
int PartRow=m_nSize%16;
//
for(int rr=0;rr < FullRows ; rr++)
{//
tmp.Format("%05X:", 8*rr);//"10000:" 8Words
prompt+=tmp;
for(int col = 0;col < 16; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
//
if(PartRow!=0)
{
tmp.Format("%05X:", 8*rr);
prompt+=tmp;
for(int col = 0;col < PartRow; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
while(col<16)
{// more spaces
prompt+=" ";//3
col++;
}
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
//
return TRUE;
}