IStorage::CreateStorage method

The CreateStorage method creates and opens a new storage object nested within this storage object with the specified name in the specified access mode.


HRESULT CreateStorage(
  [in]  const WCHAR    *pwcsName,
  [in]        DWORD    grfMode,
  [in]        DWORD    reserved1,
  [in]        DWORD    reserved2,
  [out]       IStorage **ppstg


pwcsName [in]

A pointer to a wide character null-terminated Unicode string that contains the name of the newly created storage object. The name can be used later to reopen the storage object. 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.

grfMode [in]

A value that specifies the access mode to use when opening the newly created storage object. For more information and a description of possible values, see STGM Constants.

reserved1 [in]

Reserved for future use; must be zero.

reserved2 [in]

Reserved for future use; must be zero.

ppstg [out]

A pointer, when successful, to the location of the IStorage pointer to the newly created storage object. This parameter is set to NULL if an error occurs.

Return value

This method can return one of these values.


The storage object was created successfully.


Asynchronous Storage only: Part or all of the necessary data is currently unavailable. For more information, see IFillLockBytes and Asynchronous Storage.


Not enough permissions to create storage object.


The name specified for the storage object already exists in the storage object and the grfMode parameter includes the flag STGM_FAILIFTHERE.


The storage object was not created due to a lack of memory.


The value specified for the grfMode parameter is not a valid STGM Constants value.


The specified combination of flags in the grfMode parameter is not supported.


Not a valid value for pwcsName.


The pointer specified for the storage object was not valid.


One of the parameters was not valid.


The storage object has been invalidated by a revert operation above it in the transaction tree.


The storage object was not created because there are too many open files.


The existing stream with the specified name was replaced with a new storage object containing a single stream called CONTENTS. The new storage object will be added.


If a storage with the name specified in the pwcsName parameter already exists within the parent storage object, and the grfMode parameter includes the STGM_CREATE flag, the existing storage is replaced by the new one. If the grfMode parameter includes the STGM_CONVERT flag, the existing element is converted to a stream object named CONTENTS and the new storage object is created containing the CONTENTS stream object. The destruction of the old element and the creation of the new storage object are both subject to the transaction mode on the parent storage object. Be aware that you cannot use STGM_CONVERT if you are also using STGM_CREATE.

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

  • The STGM_PRIORITY flag for nonroot storages.
  • Opening the same storage object more than once from the same parent storage. The STGM_SHARE_EXCLUSIVE flag must be specified.
  • The STGM_DELETEONRELEASE flag. If this flag is specified, the function returns STG_E_INVALIDFLAG.

If a storage object with the same name 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 | Windows Store apps]

Minimum supported server

Windows 2000 Server [desktop apps | Windows Store apps]










IID_IStorage is defined as 0000000B-0000-0000-C000-000000000046

See also

IStorage - Compound File Implementation