CFile file closing 
Author Message
 CFile file closing

Is there any way to force VC++ to actually close a CFile when the
file.close() method is called?  I have had to revert back to
fopen/fwrite/fclose to control file closure at program level.

Thanks,
Mike Ober.



Tue, 12 Mar 2002 03:00:00 GMT  
 CFile file closing
I think it does close the file right away when you call CFile::Close(), but
you might want to try something like:

    CFile m_MyFile;

   _commit(m_MyFile.m_hFile);

to get your data to flush out.  There is a CFile equivalent called:

    m_MyFile.Flush()

but it doesn't seem to always work.

HTH,

Tom

Quote:

>Is there any way to force VC++ to actually close a CFile when the
>file.close() method is called?  I have had to revert back to
>fopen/fwrite/fclose to control file closure at program level.

>Thanks,
>Mike Ober.



Tue, 12 Mar 2002 03:00:00 GMT  
 CFile file closing
I know for a fact that VC++ 4.0 (MFC 4.0) doesn't close CFiles immediately.
I needed to write an NT command script (.CMD) and execute it.  After closing
the script, it didn't seem to matter how long I waited (checked up to 5
minutes), but the file wouldn't execute - it had an open error reported by
CMD.EXE saying the file was locked by another user/application.  As soon as
I switched to K&R stdio functions, everything worked, even without a wait.

Next time, I'll try the _commit() call after my data is written and before
closing.

Thanks,
Mike Ober.


Quote:
> I think it does close the file right away when you call CFile::Close(),
but
> you might want to try something like:

>     CFile m_MyFile;

>    _commit(m_MyFile.m_hFile);

> to get your data to flush out.  There is a CFile equivalent called:

>     m_MyFile.Flush()

> but it doesn't seem to always work.

> HTH,

> Tom





Fri, 15 Mar 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Opening and closing a file on a Novell network using CFile

2. Problem with CFile::Close

3. Let me Know when to use CFile::Close();

4. CFile::Open asserts on CFile::typeText

5. CFile::Seek and CFile::Read over the network

6. Are CFile::Read() and CFile::Write() Really Unbuffered?

7. Closing a file, file handle, let me explain.

8. Catching File->Open and File->Close

9. Inserting a string at the beginning of a file with CFile

10. CFile can't read file's update lie in novell

11. Looking for CFile method to detect when file is already open

12. Millenium Read File problems (CFile)!

 

 
Powered by phpBB® Forum Software