Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

MFC Appending Data to a Document

I have a data acquisition application where I am saving large amount of data using the document/view architecture. I am periodically saving the file to the hard-disk.

To save processing time, is there a way to tell MFC to append data rather than re-write the whole data file to the hard disk when saving the file?
0
aparyani
Asked:
aparyani
1 Solution
 
zfactCommented:
Hi aparyani,
See the below info.. this i got it from MSDN.

----------------------------------------------------------
MSDN
----------------------------------------------------------
CFile::SeekToEnd
This method sets the value of the file pointer to the logical end of the file. SeekToEnd is equivalent to CFile::Seek( 0L, CFile::end ).

DWORD SeekToEnd( );
Return Value
The length of the file in bytes.

Example
// Example for the CFile::SeekToEnd method.
extern CFile cfile;
long dwActual = cfile.SeekToEnd();

----------------------------------------------------------

Sets the value of the file pointer to the logical end of the file.

ULONGLONG SeekToEnd( );
Return Value
The length of the file in bytes.

Remarks
SeekToEnd() is equivalent to CFile::Seek( 0L, CFile::end ).

Example
//example for CFile::SeekToEnd
extern CFile cfile;
ULONGLONG dwActual = cfile.SeekToEnd();
0
 
aparyaniAuthor Commented:
Thanks for the answer.


But what function in CDocument do I overide to get the CFile?  

It seems the logical function to override to get the CFile is OnSaveDocument() (code snippet below).  But MFC opens the file in Create mode and calls the serialization routine directly all withing OnSaveDocument.  This design prevents me from overriding opening the file in Truncate mode.

Do I have to completely over-ride OnSaveDocument to open the file in truncate mode?

Thanks,

Anil
0
 
hoabeoCommented:
Actually on overrided OnSaveDocument, the function calls base CDocument::OnSaveDocument, so if you comment out this line, you can gain completely control on how will you write data to file.
Remember, do not implement Serialize function on your document class.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now