IStorage::CreateStorage method (objidl.h)

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(
  const OLECHAR *pwcsName,
  DWORD         grfMode,
  DWORD         reserved1,
  DWORD         reserved2,
  IStorage      **ppstg



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.


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.


Reserved for future use; must be zero.


Reserved for future use; must be zero.


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.


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 | 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