这样可以:
CString filename=...;//你的文件名
//创建文件对象,打开文件
CFile theFile;
CFileException fileException;
//文件打开时出错
if (!theFile.Open (filename,CFile::modeRead,
&fileException))
{
//输出出错消息
TRACE("不能打开文件%s.error=%u\n",
filename,fileException.m_cause ); //文件打不开,提示并禁止用户进入下一步
AfxMessageBox("文件打开出错!");
}
//安全打开文件
else
{
//读64个字节
char string[63]={64*0};
theFile.Seek(lg,CFile::begin);
theFile.Read (&string,64);
CString p=string;
m_titleName=string;
}
CString filename=...;//你的文件名
//创建文件对象,打开文件
CFile theFile;
CFileException fileException;
//文件打开时出错
if (!theFile.Open (filename,CFile::modeRead,
&fileException))
{
//输出出错消息
TRACE("不能打开文件%s.error=%u\n",
filename,fileException.m_cause ); //文件打不开,提示并禁止用户进入下一步
AfxMessageBox("文件打开出错!");
}
//安全打开文件
else
{
//读64个字节
char string[63]={64*0};
theFile.Seek(lg,CFile::begin);
theFile.Read (&string,64);
CString p=string;
m_titleName=string;
}
解决方案 »
- m_pConnection->Open没有5个参数?
- 各位大侠请帮忙
- 我写的程序为什么在98下面报奇怪错误
- 关于com接口指针的疑问
- 关于蔡单项的information属性的动态设置。
- 新手求助!请各位指教应该用VC中哪个工程来实现我的任务
- 各位在学习vc过程中,碰到怎么也看不懂的问题,怎么办?
- 请问各们高手,现在是学JAVA好,还是VC好呢,谢谢了。我现在最多可以出24分。以后加分
- 能解决这两个问题的大侠,请和我联系。(不给分,给钱)
- 高分请教关于DBGRID另一台电脑上运行的问题?
- 关于project setting...的问题?
- windows 的BUG???????(解决者100分奉上)
{
CFile binfile;
CString str,tmpstr,totalstr;
long length;
unsigned int buflen;
DWORD haslen=0;
totalstr.Empty();
str.Empty();
tmpstr.Empty();
if(!binfile.Open(filename,CFile::modeRead,NULL))
MessageBox("不能打开文件!",NULL,MB_ICONWARNING);
else{
length=binfile.GetLength();
BYTE* lpbuf=new BYTE[length];
binfile.Read(lpbuf,length);
while(length>0)
{
if(length>2048)buflen=2048;else buflen=length;
for(unsigned int i=1;i<buflen+1;i++)
{
tmpstr.Format("0x%02x,",lpbuf[i+haslen-1]);
str+=tmpstr;
if(i%16==0)str+=0x0a;
}
str.MakeUpper();
totalstr+=str;
str.Empty();
length-=2048;
haslen+=2048;
}
binfile.Close();
}
}