Composite document in COM
Structured Storage
Under the permanent storage mechanism, common files are organized in bytes. Each file is composed of unordered bytes.
The entire file is stored in a disk in one form, and each block is discrete. When you want to read a file
When the file system manages its pointer and returns the byte stream to be read.
Com uses another more reasonable method to store files and data. This method is called structured storage. Structured Storage
The method is to store the files in a document structure after pre-processing. here we need to use two COM objects. storages
Similar to the streams. Storage object and the directory in the file system, it can contain other storage objects and streams
Object. You can understand the stream object as a file in the file system. Like a file, the stream object contains data
It is like a continuous byte block. Each composite document contains the above two objects. com, using two excuses to access the above two objects
Istorage and istream.
Why do we need structured storage?
Yes, you need to know that your composite documents include images, texts, and other data. Well, now you may want
Put it together. The previous practice is that when you want to save the file, the file system will overwrite the original file to save your new information.
It sounds like it takes a lot of time and effort, right? Yes, structured processing adopts another method. The new data is stored
The old data is stored in the new folder as the file system. The difference is that it uses a storage object.
And Stream object. Let's see what benefits it brings to us.
1. Structured Storage allows you to have full control over each independent object. You do not have to read or write the entire file each time, but can read/write you.
The expected paragraph.
2. A user can concurrently read/write the same file.
Composite document: stores different types of data in one file. For example, a Word file can contain Excel Charts and images.
Table or other data.
Now let's look at its two interfaces.
Istorage Interface
As you think, it is like a directory in the file system.
Istream Interface
It is used to read/write data to stream objects.
You can find the relevant documentation on msdn.
Let's take an example to see how they work.
The procedure is as follows:
1. First, call the stgcreatedocfile function to create a storage root object.
Stores each storage object and stream object. The stgcreatedocfile function returns an istorage interface pointer.
2. Call createstream of istorage to create a stream object. This function returns an istream pointer.
3. Call the wirte function of istream to write data such as a stream.
The source code is as follows:
# Include <objbase. H.>
Int main (INT argc, char * argv [])
{
Coinitialize (null );
Istorage * pstr;
Hresult hR = stgcreatedocfile (L "test. MCB", stgm_direct | stgm_create | stgm_readwrite | stgm_clu_exclusive, null, & pstr );
Istream * pstream;
HR = pstr-> createstream (L "mcbstream", stgm_direct | stgm_create | stgm_readwrite | stgm_clu_exclusive, 0, 0, & pstream );
Ulong name;
Char data [] = "Mahesh testing ";
Pstream-> write (data, strlen (data), & name );
Couninitialize ();
Return 0;
}
I hope this will be helpful to you and your suggestions)