Problem opening a file for read while it is open for write 
Author Message
 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



Sun, 27 Nov 2005 13:08:41 GMT  
 Problem opening a file for read while it is open for write

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.

Rob,

Try:

if (readFile.Open(fileName,CFile::modeRead | CFile::shareDenyNone))

Quote:
> If I
>stop the recording and close the writeFile then the readFile can open but
>gets an exception when it does a readFile.ReadString()

Without seeing some code, we can't guess if there's another problem.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sun, 27 Nov 2005 16:42:40 GMT  
 Problem opening a file for read while it is open for write

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.

> Rob,

> Try:

> if (readFile.Open(fileName,CFile::modeRead | CFile::shareDenyNone))

> > If I
> >stop the recording and close the writeFile then the readFile can open but
> >gets an exception when it does a readFile.ReadString()

> Without seeing some code, we can't guess if there's another problem.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq

Thanks David, I looked at that line a few times and didn't see the typo
myself.

Rob



Mon, 28 Nov 2005 12:08:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. opening file for both reading and writing

2. Opening Files For Reading and Writing in C

3. Truncating a binary file opened for read and write

4. Opening a file for both read and write.

5. C++ Library to Open/Read/Write files

6. Problem with opening binary files using open()

7. CEditView problem: opening a file that is still open

8. problems opening reading and closing files in unix

9. Problem in opening, reading..file under ISAPI (dll.....)

10. can't open file: to many files open

11. Difference between MRU File Open and Regular File Open

12. Customizing Open File Dialog -- am I right?

 

 
Powered by phpBB® Forum Software