IStream  1CBN_LW

The IStream interface supports reading and writing data to stream objects. Stream objects contain the data in a structured storage object, where storages provide the structure. Simple data can be written directly to a stream, but most frequently, streams are elements nested within a storage object. They are similar to standard files.

The IStream interface defines methods similar to the MS-DOS FAT file functions. For example, each stream object has its own access rights and a seek pointer. The main difference between a stream object and a DOS file is that streams are not opened using a file handle, but through an IStream interface pointer.

The methods in this interface present your object s data as a contiguous sequence of bytes that you can read or write. There are also methods for committing and reverting changes on streams open in transacted mode and methods for restricting access to a range of bytes in the stream.

Streams can remain open for long periods of time without consuming file system resources. The IStream::Release method is similar to a close function on a file. Once released, the stream object is no longer valid and cannot be used.

When to Implement

Implement IStream on a container or object application when you require functionality not provided by the OLE compound file implementation. The specification of IStream defines more functionality that the OLE implementation supports. In addition, if you are creating a stream object that is larger than the heap in your machine s memory and you are using a global memory handle, the compound file implementation calls GlobalRealloc internally whenever it needs more memory, which can be extremely inefficient. In this case, the preferred solution is to implement an IStream that uses memory allocated by VirtualAlloc instead of GlobalAlloc. This can reserve a large chunk of virtual address space and then commit memory within that address space as required. No data copying occurs and memory is committed only as it is needed. For more information, refer to IStream - Compound File ImplementationAQSJQX.

When to Use

Call the methods of the IStream interface from a container or application to read and write the data for an object. Since stream objects can be marshaled to other processes, applications can share the data in storage objects without having to use global memory.

Methods in Vtable Order

IUnknown1NEM0LU Methods

Description

QueryInterface2Y54585

Returns pointers to supported interfaces.

AddRef1SHW0SS

Increments the reference count.

ReleaseDUW01A

Decrements the reference count.

 

IStream Methods

Description

Read4QE_N8

Reads a specified number of bytes from the stream object into memory starting at the current seek pointer.

Write14LYPV

Writes a specified number from bytes into the stream object starting at the current seek pointer.

Seek1D93.V4

Changes the seek pointer to a new location relative to the beginning of the stream, the end of the stream, or the current seek pointer.

SetSizeHK7LP2

Changes the size of the stream object.

CopyToKJ5V0O

Copies a specified number of bytes from the current seek pointer in the stream to the current seek pointer in another stream.

CommitKJ2IZT

Ensures that any changes made to a stream object open in transacted mode are reflected in the parent storage object.

Revert_6ZBLD

Discards all changes that have been made to a transacted stream since the last IStream::CommitKJ2IZT call.

LockRegion12WH31X

Restricts access to a specified range of bytes in the stream. Supporting this functionality is optional since some file systems do not provide it.

UnlockRegionXW5TOJ

Removes the access restriction on a range of bytes previously restricted with IStream::LockRegion12WH31X.

Stat4QFLNH

Retrieves the STATSTGN9JHJ6 structure for this stream.

CloneKG4JV

Creates a new stream object that references the same bytes as the original stream but provides a separate seek pointer to those bytes.