MFC Appending Data to a Document

Posted on 2003-02-25
Medium Priority
Last Modified: 2013-11-20
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?
Question by:aparyani
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8023200
Hi aparyani,
See the below info.. this i got it from MSDN.

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 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.

Return Value
The length of the file in bytes.

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

//example for CFile::SeekToEnd
extern CFile cfile;
ULONGLONG dwActual = cfile.SeekToEnd();

Author Comment

ID: 8030461
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?



Accepted Solution

hoabeo earned 150 total points
ID: 8092288
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.

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question