CArchive::Close()
-
from MSDN:
CArchive::Close
void Close( );
throw( CArchiveException, CFileException );Remarks
Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file. No further operations on the archive are permitted. After you close an archive, you can create another archive for the same file or you can close the file.
The member function Close ensures that all data is transferred from the archive to the file, and it makes the archive unavailable. To complete the transfer from the file to the storage medium, you must first use CFile::Close and then destroy the CFile object.
i.e. CArchive::Close does NOT close the related CFile. perhaps your is not a CFile, but MSDN also states:
CFile( int hFile );
[...]
The constructor with one argument creates a CFile object that corresponds to an existing operating-system file identified by hFile. No check is made on the access mode or file type. When the CFile object is destroyed, the operating-system file will not be closed. You must close the file yourself.kiran.pinjarla wrote:
When i am calling copy or delete fn.s after these line on that file, they return unsuccess
what are you doing? :confused: hope that helps...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Thank you capallini. But if i call fp.Close() after ar.Close() i am getting an expection.
KIRAN PINJARLA
-
from MSDN:
CArchive::Close
void Close( );
throw( CArchiveException, CFileException );Remarks
Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file. No further operations on the archive are permitted. After you close an archive, you can create another archive for the same file or you can close the file.
The member function Close ensures that all data is transferred from the archive to the file, and it makes the archive unavailable. To complete the transfer from the file to the storage medium, you must first use CFile::Close and then destroy the CFile object.
i.e. CArchive::Close does NOT close the related CFile. perhaps your is not a CFile, but MSDN also states:
CFile( int hFile );
[...]
The constructor with one argument creates a CFile object that corresponds to an existing operating-system file identified by hFile. No check is made on the access mode or file type. When the CFile object is destroyed, the operating-system file will not be closed. You must close the file yourself.kiran.pinjarla wrote:
When i am calling copy or delete fn.s after these line on that file, they return unsuccess
what are you doing? :confused: hope that helps...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
dear, <pre></pre> tags are for posting code samples, not quotation, because you're breaking the page... thank you ;)
You don't know where to start ? ask a good friend
-
Thank you capallini. But if i call fp.Close() after ar.Close() i am getting an expection.
KIRAN PINJARLA
You need to call
CFile::Close
beforeCArchive::Close
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
You need to call
CFile::Close
beforeCArchive::Close
.Prasad Notifier using ATL | Operator new[],delete[][^]
prasad_som wrote:
You need to call CFile::Close before CArchive::Close.
You are wrong. CArchive does not close the file object. This is the source code...
void CArchive::Close()
{
ASSERT_VALID(m_pFile);Flush(); m\_pFile = NULL; // --> Just detaches the file pointer that's all, but doesn't close
}
Nibu thomas A Developer Programming tips[^] My site[^]
-
prasad_som wrote:
You need to call CFile::Close before CArchive::Close.
You are wrong. CArchive does not close the file object. This is the source code...
void CArchive::Close()
{
ASSERT_VALID(m_pFile);Flush(); m\_pFile = NULL; // --> Just detaches the file pointer that's all, but doesn't close
}
Nibu thomas A Developer Programming tips[^] My site[^]
I think you replying to my previous reply. Haven't you seen I've already modified it?
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Thank you capallini. But if i call fp.Close() after ar.Close() i am getting an expection.
KIRAN PINJARLA
Since the following snipped of code works fine on my system:
CFile file; MyObject obj; file.Open("foo.txt",CFile::modeWrite|CFile::modeCreate); CArchive ar(&file, CArchive::store); obj.Serialize(ar); ar.Close(); file.Close();
hope that helps. :confused:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
I think you replying to my previous reply. Haven't you seen I've already modified it?
Prasad Notifier using ATL | Operator new[],delete[][^]
prasad_som wrote:
I think you replying to my previous reply. Haven't you seen I've already modified it?
No I didn't see but still why are you saying that
CFile::Close
should be called beforeCArchive:Close
. Why what's the reason?
Nibu thomas A Developer Programming tips[^] My site[^]
-
prasad_som wrote:
I think you replying to my previous reply. Haven't you seen I've already modified it?
No I didn't see but still why are you saying that
CFile::Close
should be called beforeCArchive:Close
. Why what's the reason?
Nibu thomas A Developer Programming tips[^] My site[^]
:doh: You are right.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
Since the following snipped of code works fine on my system:
CFile file; MyObject obj; file.Open("foo.txt",CFile::modeWrite|CFile::modeCreate); CArchive ar(&file, CArchive::store); obj.Serialize(ar); ar.Close(); file.Close();
hope that helps. :confused:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Yes. I was wrong. It was not this fp.Close() which was causing the exception. It was another Close(). Anyhow learned a few new things. Thank you all.
KIRAN PINJARLA
-
kiran.pinjarla wrote:
if ar.Close() is called does it close the file pointer associcated with it(fp.Close)?
Yes, it does close CArchive. But not the CFile associated with it.
kiran.pinjarla wrote:
When i am calling copy or delete fn.s after these line on that file
What are these function ? of which class? -- modified at 3:33 Thursday 30th November, 2006 -- modified at 4:59 Thursday 30th November, 2006
Prasad Notifier using ATL | Operator new[],delete[][^]
prasad_som wrote:
You need to call CFile::Close before using CArchive::Close
In my opinion the file must be closed after closing the archive. Otherwise it will be impossible to flush the last data kept in an internal buffer of
CArchive
. If theCFile
andCArchive
objects are created on the stack, then they will be closed automatically in right order. -
prasad_som wrote:
You need to call CFile::Close before using CArchive::Close
In my opinion the file must be closed after closing the archive. Otherwise it will be impossible to flush the last data kept in an internal buffer of
CArchive
. If theCFile
andCArchive
objects are created on the stack, then they will be closed automatically in right order.Viorel. wrote:
In my opinion the file must be closed after closing the archive
You are right.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
dear, <pre></pre> tags are for posting code samples, not quotation, because you're breaking the page... thank you ;)
You don't know where to start ? ask a good friend
OK, dear... :):-D:) but what does it mean because you're breaking the page...? I cannot understand :confused:, please explain to me. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.