
Problem opening a file for read while it is open for write
I have a history class that keeps a history of user commands. It opens a
file for write and the app calls an addEvent() method that writes to the
file. The open looks like this:
CStdioFile writeFile;
CFileException ex;
if(writeFile.Open(fullFileName, CFile::modeCreate | CFile::modeNoTruncate |
CFile::modeWrite | CFile::shareDenyWrite, &ex))
{
sprintf(str, "Recording started for %s on %s %s\nInput: %s\nOutput: %s\n",
fullFileName, date, time, infileName, outputFile);
writeFile.WriteString( str);
writeFile.Flush();
Quote:
}
I also need a dialog that can display the contents of the history file. I
try to open the file in the dioalogs InitDialog() method but I run into
problems. The open looks like this:
CStdioFile readFile;
if (readFile.Open(fileName,CFile::modeRead || CFile::shareDenyNone))
This always fails to open if the other class has it open for write. If I
stop the recording and close the writeFile then the readFile can open but
gets an exception when it does a readFile.ReadString()
Am I doing this all wrong?
Rob