IStorage::CreateStream method

The CreateStream method creates and opens a stream object with the specified name contained in this storage object. All elements within a storage objects, both streams and other storage objects, are kept in the same name space.


HRESULT CreateStream(
  const OLECHAR *pwcsName,
  DWORD         grfMode,
  DWORD         reserved1,
  DWORD         reserved2,
  IStream       **ppstm



A pointer to a wide character null-terminated Unicode string that contains the name of the newly created stream. The name can be used later to open or reopen the stream. The name must not exceed 31 characters in length, not including the string terminator. The 000 through 01f characters, serving as the first character of the stream/storage name, are reserved for use by OLE. This is a compound file restriction, not a structured storage restriction.


Specifies the access mode to use when opening the newly created stream. For more information and descriptions of the possible values, see STGM Constants.


Reserved for future use; must be zero.


Reserved for future use; must be zero.


On return, pointer to the location of the new IStream interface pointer. This is only valid if the operation is successful. When an error occurs, this parameter is set to NULL.

Return value

This method can return one of these values.


If a stream with the name specified in the pwcsName parameter already exists and the grfMode parameter includes the STGM_CREATE flag, the existing stream is replaced by a newly created one. Both the destruction of the old stream and the creation of the new stream object are subject to the transaction mode on the parent storage object.

The COM-provided compound file implementation of the IStorage::CreateStream method does not support the following behaviors:

  • The STGM_DELETEONRELEASE flag is not supported.
  • Transacted mode (STGM_TRANSACTED) is not supported for stream objects.
  • Opening the same stream more than once from the same storage is not supported. The STGM_SHARE_EXCLUSIVE sharing-mode flag must be specified in the grfMode parameter.
If the stream already exists and grfMode is set to STGM_FAILIFTHERE, this method fails with the return value STG_E_FILEALREADYEXISTS.


Minimum supported client Windows 2000 Professional [desktop apps | UWP apps]
Minimum supported server Windows 2000 Server [desktop apps | UWP apps]
Target Platform Windows
Header objidl.h
Library Uuid.lib
DLL Ole32.dll

See also

IStorage - Compound File Implementation