Last modified: July 23, 2011

Applies to: Outlook

Implements a storage object to access a stream.

HRESULT IStorageFromStream(
  LPCIID lpInterface,
  ULONG ulFlags,
  LPSTORAGE FAR * lppStorageOut


[in] A pointer to a stream object.


[in] A pointer to the interface identifier (IID) that represents the interface to be used to access the stream pointed to by lpUnkIn. Any of the following values are valid: IID_IStream, IID_ILockBytes, or null, which indicates that the IStream interface should be used to access the stream.


[in] A bitmask of flags that controls how the storage object is to be created relative to the stream object. By default, the storage is created with read-only access and the stream starts at position zero in the storage. The following flags can be set:


A new storage object should be created for the stream object.


The storage object should start at the current position of the stream.


The caller should have read/write permission to the returned storage object.


The storage object should start at position zero.


[out] A pointer to a pointer to the storage object.


The storage object was successfully created.

The IMAPISupport::IStorageFromStream method is implemented for all service provider support objects. Service providers call IStorageFromStream to create a storage object to use for opening particular properties. Service providers that have their own implementation of the IStorage interface do not need to call IStorageFromStream.

The storage object created by IStorageFromStream calls the stream's IUnknown::AddRef method to increment its reference count and then decrements the count when the storage is released.

When the IMAPIProp::OpenProperty method of one of your objects is called to open a property with the IStorage interface, perform the following tasks:

  1. Open a stream object with read/write permission for the property.

  2. Internally mark the property stream as a storage object.

  3. Call IStorageFromStream to generate a storage object.

  4. Return a pointer to this storage object.

If you implement additional interfaces that use the storage object, create an object that wraps the storage object and implement a higher level IUnknown::QueryInterface method.

Do not allow a property to be opened with the IStream interface if it was created with IStorage. Conversely, do not allow a property to be opened with the IStorage interface if it was created with IStream.

With one exception, it is acceptable to use the IStreamDocfile interface to stream a storage object from one container to another, but the IID_IStreamDocfile interface identifier must be passed in the OpenProperty method's lpInterface parameter.