Structured File Storage Technology and Application
SinceWindowsAfter the launch of the system,MicrosoftThe company has been committed to improving and adopting new file storage methods, of which structured storage is the most respected by Microsoft. This technology adopts the com technical architecture and is currently widely used in office
The storage is structured, and Microsoft promotes the application of this storage method.SDK provides a complete set of help documents and related materials for this technology.
The so-called structured storage method actually applies the principle of the tree file system to a single file, so that a single file can contain "subdirectories" like a file system ", "sub-directories" can also contain deeper "sub-directories". Each "directory" can contain multiple files, save the content that originally requires multiple file Storages to a single file in a tree structure and hierarchy. For users who are clear about disk storage, it is easy to understand this storage method can greatly improve the efficiency of disk space usage. In addition, the ownership and classification relationship of the content can be clearly defined in a single file. In addition, a large number of distribution files are not required in the software distribution process, and data files can be attributed to one file.
This article describes the structured storage technologies provided by windows and uses the Delphi language for implementation.
I. Introduction to Structured Storage Technology
The Windows SDK provides detailed information about structured storage. As mentioned above, the technology adopts the com architecture, so the provided functions are used with interfaces, including istorage, istream,IENumstatstg is the three most important interfaces for structured storage ).
1. istorage
The istorage interface supports functions related to creating and managing structured storage files. It can contain multiple other istorages, which are equivalent to "sub-directories" in the file system, or multiple istreams described below, which is equivalent to a specific "single file" in the file system ". A structured storage file can be used to represent its structure.
We can see that any structured storage file has a root istorage. This interface can contain multiple level-1 sub-istorage. level-1 sub-istorage can contain multiple level-2 sub-istorage, the hierarchy and tree structure of Structured Storage files are formed in sequence, and each istorage can contain any istream, which is equivalent to a single file in the file system.
The main functions of istorage include:
1.1 stgcreatedocfile
This function creates a structured storage file and returns the istorage interface. The function format is hresult stgcreatedocfile (
Const wchar * pwcsname, // name of the structured storage file to be created
DWORD grfmode, // access mode for structured storage files
DWORD reserved, // reserved, must be zero
Istorage ** ppstgopen // The returned istorage interface variable
);
1.2 stgopenstorage
This function opens a structured storage file and returns an istorage excuse. The format of the function is hresult stgopenstorage (
Const wchar * pwcsname, // structured storage file to be opened
Istorage * pstgpriority, // The previously opened istorage is generally Nil
DWORD grfmode, // file opening Mode
SNB snbexclude, // represents the SNB structure, which can be nil
DWORD reserved, // reserved, must be 0
Istorage ** ppstgopen // The returned istorage interface variable
);
1.3 stgisstoragefile
This function determines whether the specified file is stored in a structured manner. The function format is:
Hresult stgisstoragefile (
Const wchar * pwcsname // name of the file to be determined
);
1.4 createstorage
This function is a function provided by the istorage interface. It creates an istorage for istorage, that is, creating a "subdirectory ". The function format is:
Hresult createstorage (
Const wchar_t * pwcsname, // name of the "sub" istorage to be created
DWORD grfmode, // "sub" istorage Access Mode
DWORD reserved1, // reserved, must be zero
DWORD reserved2, // reserved, must be zero
Istorage ** ppstg // The returned istorage interface variable
);
1.5 createstream
This function is a function provided by the istorage interface. It creates an istream for istorage, which is equivalent to creating a single "File ". The function format is:
Hresult createstream (
Const wchar_t * pwcsname, // name of the "sub" istream to be created
DWORD grfmode, // "sub" istream Access Mode
DWORD reserved1, // reserved, must be zero
DWORD reserved2, // reserved, must be zero
Istream ** ppstm // returned istream interface variable
);
1.6 openstorage
This function is a function provided by the istorage interface. Open the sub-istorage of the current istorage. The function format is:
Hresult openstorage (
Const wchar_t * pwcsname, // sub-istorage name
Istorage * pstgpriority, // The previously opened istorage is generally Nil
DWORD grfmode, // enable the access mode of istorage
SNB snbexclude, // SNB module, generally Nil
DWORD reserved, // reserved, must be zero
Istorage ** ppstg // The returned istorage interface variable
);
1.7 openstream
This function is a function provided by the istorage interface. Open the sub-istream of the current istorage. The function format is:
Hresult openstream (
Const wchar_t * pwcsname, // The istream name to open
Void * reserved1, // reserved, must be nil
DWORD grfmode, // enabled istream Access Mode
DWORD reserved2, // reserved, must be zero
Istream ** ppstm // returned istream interface variable
);
1.8 enumelements
This function is a function provided by the istorage interface. It obtains the enumerated ienumstatstg interface of the content contained in istorage. You can use ienumstatstg to obtain the tree structure and hierarchy of Structured Storage files. Ienumstatstg will be introduced later. Its function format is as follows:
Hresult enumelements (
DWORD reserved1, // reserved, must be zero
Void * reserved2, // reserved, must be nil
DWORD reserved3, // reserved, must be 0
Ienumstatstg ** ppenum // The returned ienumstatstg interface variable
);
1.9 moveelementto
This function is a function provided by the istorage interface. It moves or copies the "sub" istorage or "sub" istream under istorage. The function format is:
Hresult moveelementto (
Const wchar_t pwcsname, // The istorage and istream names to be moved or copied
Istorage * pstgdest, // name of the istorage to be moved or copied
Lpwstr pwcsnewname, // name after moving or copying to a new "destination"
DWORD grfflags // indicates whether to move or copy
);
1.10 renameelement and destroyelement
This is a function provided by the istorage interface. You can rename and delete istorage. The function format is omitted.
The istorage interface also provides other functions. For more information, see Windows SDK.API related functions.
2. istream
The istream interface is nested in istorage. Its main function is to read data from structured storage files and write data to structured storage files. This interface provides the following functions:
2.1
Read: read data from istream. The function format is as follows:
Hresult read (
Void * PV, // read the data and store it in the Variable
Ulong CB, // number of bytes to be read
Ulong *PCBread // the actual number of bytes read
);
2.2 write: Write Data to istream. The function format is as follows:
Hresult write (
Void const * PV, // constant to write data
Ulong CB, // number of bytes to be written
Ulong * bytes written // actual number of bytes written
);
2.3 seek: the object pointer for reading and writing data. Its function format is:
Hresult seek (
Large_integer DLIBMOve, // The number of bytes that the file pointer moves
DWORD dworigin, // The file pointer moves byte from that location
Ularge_integer * plibnewposition // the position of the new pointer can be nil
);
3,IENumstatstg
The ienumstatstg interface is used to browse structured storage files in a tree. Its functions are relatively simple and mainly include the following:
Hresult next (ulong Celt, statstg * rgelt, ulong * pceltfetched)
Hresult SKIP (ulong CELT)
Hresult reset (void)