Hi all :)
I am trying to get to grips with file handling under MFC and it has me slightly baffled. I am using a CFile object to interface with the file - but my problem is that the buffer reads the entire 1024 bytes.. This of course has the nasty side effect of printing garbage in the messagebox. Is there a better way of reading the file such that you only read the data in the file?
Thanks.Code:BYTE buffer[0x0400]; // 1KB buffer
CFile file (_T("File.txt"), CFile::modeRead);
DWORD dwBytesRemaining = file.GetLength();
while(dwBytesRemaining)
{
UINT nBytesRead = file.Read(buffer, sizeof(buffer));
dwBytesRemaining -= nBytesRead;
}
MessageBox((char*)buffer);