5,692,513 members and growing! (13,883 online)
Email Password   helpLost your password?
Desktop Development » Files and Folders » General     Intermediate

Structured Storage - The DocFile

By Andrew Peace

A wrapper class for easy use of OLE structured storage.
VC6, C++Windows, NT4, MFC, VS6, Visual Studio, Dev

Posted: 16 Feb 2000
Updated: 14 Jul 2001
Views: 109,102
Bookmarked: 51 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
29 votes for this Article.
Popularity: 6.63 Rating: 4.53 out of 5
1 vote, 5.6%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 5.6%
4
16 votes, 88.9%
5

Introduction

Structured storage is something which, when done using the plain Windows API, seems overly complicated; much more so than is needed. The aim of this article is to briefly introduce you to the concepts behind structured storage, and then provide a helper class to simplify its usage.

The idea behind structured storage is that a single file can itself contain a basic filing system. Its main reason for existence was to help with OLE documents: embedded objects are simply save as separate 'streams' within the single file. Here is a diagram which illustrates this concept:

STRUCTURED STORAGE FILE
  • First_stream
  • Second_stream
  • A_storage
    • Stream_in_stg

Although this technology is primarily for use in OLE, it can be put to other uses. In order to help you access the functionality of this powerful tool easily, I have created a helper class, namely CSSFile, to aid in the creation, and modification of structured storage files.

Updates

If you have used this class previously, you will most likely wish to update your code to use the latest version. Here are the main differences (note that the interface remains the same):

  • The use of const references for faster parameter passing
  • Quicker operation as a result of reduced 'waste' code
  • Removal of un-needed variables and code from the class
  • Better arrangement of source and header files.
  • Integration of help into the article rather than as a HTML Help download.
  • Proper UNICODE awareness

Usage of the class

Whilst the class is fairly straightforward, I have listed the functions and their interfaces below to aid your usage of the class:

Function: CreateSSFile(...)

Parameters

filename - the name of the file to be created

mode - the mode of access for the file

Return value

'true' if the file was successfully created

Function: OpenSSFile(...)

Parameters

filename - the name of the file to open

mode - the mode of access for the file

Return value

'true' if the file was successfully opened

Function: Attach(...)

Parameters

pNews - the storage this object should hook

Return value

The previous storage being managed by the object

Function: Detach(...)

No Parameters

Return value

The previous storage being managed by the object

Function: Close()

No Parameters

No Return value

Function: CreateStorage(...)

Parameters

name - the name of the storage to create (will be created within the current path inside the root storage)

enter - enter the storage after creation?

mode - the mode of access for the storage

Return value

'true' if the storage was successfully created

Function: EnterStorage(...)

Parameters

name - the name of the storage to open

mode - the mode of access for the storage

Return value

'true' if the storage was successfully opened

Function: ExitStorage(...)

No Parameters

Return value

'true' if the storage path was moved up a level

Function: CreateStream(...)

Parameters

name - the name of the stream to create

sf - a COleStreamFile into which the stream is opened

mode - the mode of access for the stream

Return value

'true' if the stream was successfully created

Function: OpenStream(...)

Parameters

name - the name of the stream to open

sf - a COleStreamFile into which the stream is opened

mode - the mode of access for the stream

Return value

'true' if the stream was successfully opened

Function: DestroyElement(...)

Parameters

name - the name of the element to destroy

Return value

'true' if the element was successfully destroyed

Function: GetRootStorage()

No Parameters

Return value

The root of the currently open storage

Function: GetCurrentStorage()

No Parameters

Return value

The currently open storage

Function: IsOpen()

No Parameters

Return value

Whether a file is currently being managed by the object

Function: GetFilename()

No Parameters

Return value

The filename of the root storage

Function: GetPath(...)

Parameters

SepChar - the character to be used to separate the paths in the storages (i.e. Windows uses '\' for standard file system paths).

Return value

The current path within the storage (including the filename of the root storage).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Andrew Peace


Andrew is currently a student at the University of Cambridge, working towards a degree in Computer Science. The word 'working' is used here in a vague sense, with the hope that the reader will realise that the same sentence contained the word 'student'.

Aside from computing he has a strong interest in music, and enjoys the outdoors, particularly when the weather permits going out in them... To Andrew, cycling is fun, sailing is more fun, and the odd camping trip and walk is certainly what the doctor ordered.

In terms of programming experience, he first started writing programs for the Commodore Amiga using BASIC, after which he learned the joys of C and has never looked back. Since, he has added C++ and C# to his repotoire, along with a bunch of other crazy languages like ML that they like to teach in college.
Location: United Kingdom United Kingdom

Other popular Files and Folders articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 34 (Total in Forum: 34) (Refresh)FirstPrevNext
GeneralWrapped into a dll to get info from outlook msg filesmemberCalvin Streeting12:32 10 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberWojan4:13 11 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberCalvin Streeting14:13 11 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberWojan15:51 11 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberCalvin Streeting22:54 11 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberWojan3:46 12 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberCalvin Streeting4:51 12 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberCalvin Streeting13:53 12 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberWojan15:20 12 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberAndrew Peace12:32 15 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberCalvin Streeting14:28 15 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberCalvin Streeting15:07 17 Jan '07  
GeneralRe: Wrapped into a dll to get info from outlook msg filesmemberRahulOP2:42 19 Jan '07  
GeneralHow to write doc filemembervbhole0:18 10 Sep '05  
Generalhow to rename Ele Elementmemberriverclod18:47 15 May '05  
GeneralWord OleLoad (Structured Storage) Problem !membervishalmore19:07 26 Nov '04  
GeneralRe: Word OleLoad (Structured Storage) Problem !memberAndrew Peace2:47 27 Nov '04  
GeneralRe: Word OleLoad (Structured Storage) Problem !membervishalmore3:22 27 Nov '04  
GeneralOptimizing file size...memberTamer22:49 13 Oct '04  
GeneralHow to save HTMLs into single?memberAlick Xiong23:47 18 Jun '04  
GeneralRe: How to save HTMLs into single?memberPeter Weyzen16:49 23 Aug '04  
GeneralRe: How to save HTMLs into single?sussanoymous2:33 12 Mar '05  
GeneralRe: How to save HTMLs into single?memberPeter Weyzen13:17 12 Mar '05  
GeneralIViewObject2::Draw()'s problem?sussArnoldZ20:28 20 Oct '03  
GeneralbugmemberGao yihong18:36 9 Oct '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 14 Jul 2001
Editor: Chris Maunder
Copyright 2000 by Andrew Peace
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project