|
-
April 25th, 2011, 06:20 PM
#1
Trouble reading file using CFile
Ive been trying to use the Open and Save FileDlg in MFC and then use that GetFileName to allow me to read a log file and then update a list control i have in a dialog form. Now when i run the small dialog app and click the open dialog button. It allows me to browse to the file and select it and when i press ok it comes up with "an unamed file was not found" Ive been looking at lots of CFile::Read examples but i just cant seem to see what im doing wrong here. Any ideas?
Code:
void CReaderDlg::OnBnClickedButton1()
{
char strFilter[] = { "Log Files (*.log)|*.log|All Files (*.*)|*.*||" };
CFileDialog FileDlg(TRUE,".log",NULL,0,strFilter);
if(FileDlg.DoModal()==IDOK)
{
CFile file;
DWORD filesize;
char buffer[2000];
filesize = file.GetLength();
file.Open(FileDlg.GetFileName(),CFile::modeReadWrite);
file.Read(buffer,filesize);
m_ListChat.InsertItem(0,buffer);
file.Close();
}
else
{
return;
}
}
-
April 25th, 2011, 07:57 PM
#2
Re: Trouble reading file using CFile
You might want to try FileDlg.GetPathName() instead of FileDlg.GetFileName().
-
April 25th, 2011, 08:17 PM
#3
Re: Trouble reading file using CFile
How is GetLength() supposed to work when you haven't specified the file name to CFile yet?
What happens if the size of the file is greater than 2000?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|