Click here to Skip to main content
Click here to Skip to main content

Structured Storage - The DocFile

, 14 Jul 2001
Rate this:
Please Sign up or sign in to vote.
A wrapper class for easy use of OLE structured storage.

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

Share

About the Author

Andrew Peace

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

Comments and Discussions

 
Questionadd stream failer Pinmemberltcnba198628-Mar-13 20:32 
Questionoutlook msg Pinmembermiguel_19-Apr-12 12:21 
GeneralWrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting10-Jan-07 11:32 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberWojan11-Jan-07 3:13 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting11-Jan-07 13:13 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberWojan11-Jan-07 14:51 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting11-Jan-07 21:54 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberWojan12-Jan-07 2:46 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting12-Jan-07 3:51 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting12-Jan-07 12:53 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberWojan12-Jan-07 14:20 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberAndrew Peace15-Jan-07 11:32 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting15-Jan-07 13:28 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberCalvin Streeting17-Jan-07 14:07 
GeneralRe: Wrapped into a dll to get info from outlook msg files PinmemberRahulOP19-Jan-07 1:42 
QuestionHow to write doc file Pinmembervbhole9-Sep-05 23:18 
Questionhow to rename Ele Element Pinmemberriverclod15-May-05 17:47 
GeneralWord OleLoad (Structured Storage) Problem ! Pinmembervishalmore26-Nov-04 18:07 
GeneralRe: Word OleLoad (Structured Storage) Problem ! PinmemberAndrew Peace27-Nov-04 1:47 
GeneralRe: Word OleLoad (Structured Storage) Problem ! Pinmembervishalmore27-Nov-04 2:22 
GeneralOptimizing file size... PinmemberTamer13-Oct-04 21:49 
QuestionHow to save HTMLs into single? PinmemberAlick Xiong18-Jun-04 22:47 
AnswerRe: How to save HTMLs into single? PinmemberPeter Weyzen23-Aug-04 15:49 
GeneralRe: How to save HTMLs into single? Pinsussanoymous12-Mar-05 1:33 
GeneralRe: How to save HTMLs into single? PinmemberPeter Weyzen12-Mar-05 12:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 15 Jul 2001
Article Copyright 2000 by Andrew Peace
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid