About carchive class

Source: Internet
Author: User
MFC provides the carchive class to implement data buffer read and write, and defines the storage and read solutions for class objects.
There are two ways to create a carchive object:
    • Implicitly create a carchive object using the framework
    • Create a carchive object explicitly
Implicitly create a carchive object using the framework

The most common and easiest way is to make the framework represent the "save", "Save as", and "open" commands on the "file" menu to create a documentCarchiveObject.

The following are applicationsProgramWhen a user issues the "Save as" command from the "file" menu, the operations performed by the framework:

    1. The "Save as" dialog box is displayed and the file name is obtained from the user.
    2. Open the file named by the userCfileObject.
    3. Create to point to thisCfileObjectCarchiveObject. In the createCarchiveThe framework sets the mode to "Storage" (that is, writing or serialization), rather than "loading" (that is, reading or deserialization ).
    4. Call inCdocumentTheSerializeFunction, SetCarchiveObject Reference is passed to this function.

ThenSerializeFunction writes dataCarchiveObject (just explained ). SlaveSerializeWhen a function is returned, the framework is destroyed first.CarchiveObject, and then destroyCfileObject.

Therefore, if you want the framework to create a documentCarchiveObject. All you need to do is to write files to and read files from the archive.SerializeFunction. You must alsoSerializeAny function that serializes directly or indirectlyCobjectImplementation of derived objectsSerialize.

Create a carchive object explicitly

In addition to serialization of documents through the framework, it may also be required in other scenariosCarchiveObject. For example, data that may be serialized to or from the clipboardCsharedfileObject Representation. Alternatively, you may need to use the user interface to save files different from those provided by the framework. In this case, you can explicitly createCarchiveObject. Perform the following procedure in the same way as the framework.

Create a carchive object explicitly

    1. StructureCfileObject or slaveCfileThe exported object.
    2. As shown in the following exampleCfileObjectCarchiveConstructor:
      Cfile thefile; thefile. Open (..., cfile: modewrite); carchive archive (& thefile, carchive: Store );

      CarchiveThe second parameter of the constructor is to specify whether the archive will be used to store data in the file or the enumerated values used to load data from the file. ObjectSerializeThe function callsIsstoringFunction to check the status.

WhenCarchiveWhen the object stores data or loads data from the object, close the object. AlthoughCarchiveObject (andCfileObject) will automatically close the archive (and file), the good way is to explicitly execute, because this makes it easier to recover from errors.
Disable carchive objects

    • The following example illustrates how to disableCarchiveObject:
      Archive. Close (); thefile. Close ();
Refer to msdn, not created by myself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.