Link to home
Start Free TrialLog in
Avatar of GGRUNDY
GGRUNDY

asked on

Get an IStream given a file on disk

Hi,
I have a file on disk.
I want a COM IStream interface (which will only be used for sequential reading).
It would be real nice if someone could tell me a more sensible way to get from A to B, without having to:
a) GlobalAlloc
b) Load my entire file to memory; and
c) CreateStreamOnHGlobal.

Fingers crossed

Avatar of jkr
jkr
Flag of Germany image

Why not using 'StgOpenStorage()'?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GGRUNDY
GGRUNDY

ASKER

I thought StgOpenStorage opened compound storage files. The file I want to hook up to my input IStream is just a raw data file. Am I missing something?
Avatar of GGRUNDY

ASKER

Oh!!! Can I use StgOpenStorage on the directory which contains my file?????
Avatar of GGRUNDY

ASKER

>>>Oh!!! Can I use StgOpenStorage on the directory which contains my file?????
NO :-(

But I just found the following on MSDN

Streams on Existing Files
Because streams and files are so close in nature, it seems natural that you should be able to create a stream object that accesses a file through IStream instead of through a file handle. OLE doesn't currently provide a simple API function for this exact purpose, although for small files you can easily load the file into memory and create a stream on that memory.

Structured Storage does, however, define a special access mode that allows a client to open an existing file as if it were a root storage, and the contents of the existing file are exposed through a stream named CONTENTS (big surprise). So while you can't simply open a stream on top of a file, you can open a root storage and then open a stream.
Avatar of GGRUNDY

ASKER

:-( :-( :-( :-(
Before anyone gets too excited about the availabilty of a stream named contents...
Turns out only to be available if you open the storage STGM_CONVERT which (big surprise) trashes your file.
Avatar of GGRUNDY

ASKER

SHCreateStreamOnFileEx is available but only XP.
So I guess I'm going to have to write my own code.
Avatar of GGRUNDY

ASKER

Hi JKR, What do you think I should do about finalising this question?
Avatar of GGRUNDY

ASKER

I've decided to accept JKRs answer rather than delete the question. Because I know when I go looking for solutions it often saves me heaps of fruitless searching when I find an "It can't be done" answer.