Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC
Article

Structured Storage - The DocFile

Rate me:
Please Sign up or sign in to vote.
4.86/5 (18 votes)
14 Jul 2001 209K   5.5K   75   36
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


Written By
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 Pin
ltcnba198628-Mar-13 20:32
ltcnba198628-Mar-13 20:32 
Questionoutlook msg Pin
miguel_19-Apr-12 12:21
miguel_19-Apr-12 12:21 
GeneralWrapped into a dll to get info from outlook msg files Pin
Calvin Streeting10-Jan-07 11:32
Calvin Streeting10-Jan-07 11:32 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan11-Jan-07 3:13
Wojan11-Jan-07 3:13 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting11-Jan-07 13:13
Calvin Streeting11-Jan-07 13:13 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan11-Jan-07 14:51
Wojan11-Jan-07 14:51 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting11-Jan-07 21:54
Calvin Streeting11-Jan-07 21:54 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan12-Jan-07 2:46
Wojan12-Jan-07 2:46 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting12-Jan-07 3:51
Calvin Streeting12-Jan-07 3:51 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting12-Jan-07 12:53
Calvin Streeting12-Jan-07 12:53 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan12-Jan-07 14:20
Wojan12-Jan-07 14:20 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Andrew Peace15-Jan-07 11:32
Andrew Peace15-Jan-07 11:32 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting15-Jan-07 13:28
Calvin Streeting15-Jan-07 13:28 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting17-Jan-07 14:07
Calvin Streeting17-Jan-07 14:07 
Ok I got the project registerd on sourcforge and for your information here is the url
https://sourceforge.net/projects/ssfiledll/

many thanks

p.s now i need to see if i can get to the IMessage stored in outlook msg files and thus get more information (oh and learn more c++ Smile | :) )
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
RahulOP19-Jan-07 1:42
RahulOP19-Jan-07 1:42 
QuestionHow to write doc file Pin
Member 3618579-Sep-05 23:18
Member 3618579-Sep-05 23:18 
Questionhow to rename Ele Element Pin
riverclod15-May-05 17:47
riverclod15-May-05 17:47 
GeneralWord OleLoad (Structured Storage) Problem ! Pin
vishalmore26-Nov-04 18:07
vishalmore26-Nov-04 18:07 
GeneralRe: Word OleLoad (Structured Storage) Problem ! Pin
Andrew Peace27-Nov-04 1:47
Andrew Peace27-Nov-04 1:47 
GeneralRe: Word OleLoad (Structured Storage) Problem ! Pin
vishalmore27-Nov-04 2:22
vishalmore27-Nov-04 2:22 
GeneralOptimizing file size... Pin
Tamer13-Oct-04 21:49
Tamer13-Oct-04 21:49 
QuestionHow to save HTMLs into single? Pin
Tcpip200518-Jun-04 22:47
Tcpip200518-Jun-04 22:47 
AnswerRe: How to save HTMLs into single? Pin
Peter Weyzen23-Aug-04 15:49
Peter Weyzen23-Aug-04 15:49 
GeneralRe: How to save HTMLs into single? Pin
Anoymous12-Mar-05 1:33
Anoymous12-Mar-05 1:33 
GeneralRe: How to save HTMLs into single? Pin
Peter Weyzen12-Mar-05 12:17
Peter Weyzen12-Mar-05 12:17 

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

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