Click here to Skip to main content
11,437,816 members (31,814 online)
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 Pin
ltcnba198628-Mar-13 21:32
memberltcnba198628-Mar-13 21:32 
Questionoutlook msg Pin
miguel_19-Apr-12 13:21
membermiguel_19-Apr-12 13:21 
GeneralWrapped into a dll to get info from outlook msg files Pin
Calvin Streeting10-Jan-07 12:32
memberCalvin Streeting10-Jan-07 12:32 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan11-Jan-07 4:13
memberWojan11-Jan-07 4:13 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting11-Jan-07 14:13
memberCalvin Streeting11-Jan-07 14:13 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan11-Jan-07 15:51
memberWojan11-Jan-07 15:51 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting11-Jan-07 22:54
memberCalvin Streeting11-Jan-07 22:54 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan12-Jan-07 3:46
memberWojan12-Jan-07 3:46 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting12-Jan-07 4:51
memberCalvin Streeting12-Jan-07 4:51 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting12-Jan-07 13:53
memberCalvin Streeting12-Jan-07 13:53 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Wojan12-Jan-07 15:20
memberWojan12-Jan-07 15:20 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Andrew Peace15-Jan-07 12:32
memberAndrew Peace15-Jan-07 12:32 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting15-Jan-07 14:28
memberCalvin Streeting15-Jan-07 14:28 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
Calvin Streeting17-Jan-07 15:07
memberCalvin Streeting17-Jan-07 15:07 
GeneralRe: Wrapped into a dll to get info from outlook msg files Pin
RahulOP19-Jan-07 2:42
memberRahulOP19-Jan-07 2:42 
QuestionHow to write doc file Pin
vbhole10-Sep-05 0:18
membervbhole10-Sep-05 0:18 
Questionhow to rename Ele Element Pin
riverclod15-May-05 18:47
memberriverclod15-May-05 18:47 
GeneralWord OleLoad (Structured Storage) Problem ! Pin
vishalmore26-Nov-04 19:07
membervishalmore26-Nov-04 19:07 
GeneralRe: Word OleLoad (Structured Storage) Problem ! Pin
Andrew Peace27-Nov-04 2:47
memberAndrew Peace27-Nov-04 2:47 
GeneralRe: Word OleLoad (Structured Storage) Problem ! Pin
vishalmore27-Nov-04 3:22
membervishalmore27-Nov-04 3:22 
GeneralOptimizing file size... Pin
Tamer13-Oct-04 22:49
memberTamer13-Oct-04 22:49 
QuestionHow to save HTMLs into single? Pin
Alick Xiong18-Jun-04 23:47
memberAlick Xiong18-Jun-04 23:47 
AnswerRe: How to save HTMLs into single? Pin
Peter Weyzen23-Aug-04 16:49
memberPeter Weyzen23-Aug-04 16:49 
GeneralRe: How to save HTMLs into single? Pin
anoymous12-Mar-05 2:33
sussanoymous12-Mar-05 2:33 
GeneralRe: How to save HTMLs into single? Pin
Peter Weyzen12-Mar-05 13:17
memberPeter Weyzen12-Mar-05 13:17 
QuestionIViewObject2::Draw()'s problem? Pin
ArnoldZ20-Oct-03 20:28
sussArnoldZ20-Oct-03 20:28 
Generalbug Pin
Gao yihong9-Oct-03 18:36
memberGao yihong9-Oct-03 18:36 
GeneralRe: bug Pin
Anonymous20-Oct-03 20:21
sussAnonymous20-Oct-03 20:21 
QuestionGet the text in word document??? Pin
nathania1-Aug-03 5:28
membernathania1-Aug-03 5:28 
AnswerRe: Get the text in word document??? Pin
romeok1-Aug-03 15:05
memberromeok1-Aug-03 15:05 
GeneralThanks Pin
mirex10-Mar-03 2:50
membermirex10-Mar-03 2:50 
GeneralWhats this for ? Program crashes often also ... Pin
Anonymous16-May-02 9:30
memberAnonymous16-May-02 9:30 
GeneralRe: Whats this for ? Program crashes often also ... Pin
Andrew Peace11-Jul-02 13:19
editorAndrew Peace11-Jul-02 13:19 
GeneralRe: Whats this for ? Program crashes often also ... Pin
Norm Almond5-Aug-02 22:34
memberNorm Almond5-Aug-02 22:34 
GeneralNice... Pin
dswigger12-Oct-01 6:54
memberdswigger12-Oct-01 6:54 
GeneralTip for using demo project Pin
Tim Howland8-Mar-00 7:52
sussTim Howland8-Mar-00 7:52 

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 | Terms of Use | Mobile
Web02 | 2.8.150506.1 | Last Updated 15 Jul 2001
Article Copyright 2000 by Andrew Peace
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid