Creates a new compound file storage object using the COM-provided compound file implementation for the IStorage interface.
HRESULT StgCreateDocfile(
const WCHAR * pwcsName, //Points to path of compound file to
// create
DWORD grfMode, //Specifies the access mode for opening the
// storage object
DWORD reserved, //Reserved; must be zero
IStorage ** ppstgOpen //Points to location for returning the new
// storage object
);
This function can also return any file system errors or Win32 errors wrapped in an HRESULT.
The StgCreateDocfile function creates a new storage object using the COM-provided, compound-file implementation for the IStorage interface. The name of the open compound file can be retrieved by calling the IStorage::Stat method.
StgCreateDocfile creates the file if it does not exist. If it does exist, the use of the STGM_CREATE, STGM_CONVERT, and STGM_FAILIFTHERE flags in the grfMode parameter indicate how to proceed. See the STGM enumeration for more information on these values.
If the compound file is opened in transacted mode (the grfMode parameter specifies STGM_TRANSACTED) and a file with this name already exists, the existing file is not altered until all outstanding changes are committed. If the calling process lacks write access to the existing file (because of access control in the file system), the grfMode parameter can only specify STGM_READ and not STGM_WRITE or STGM_READWRITE. The resulting new open compound file can still be written to, but a subsequent commit operation will fail (in transacted mode, write permissions are enforced at commit time).
Specifying STGM_SIMPLE provides a much faster implementation of a compound file object in a limited, but frequently-used case. This can be used by applications that require a compound file implementation with multiple streams and no storages. The simple mode does not support all of the methods on IStorage. For more information, refer to the STGM enumeration.
If the grfMode parameter specifies STGM_TRANSACTED and no file yet exists with the name specified by the pwcsName parameter, the file is created immediately. In an access-controlled file system, the caller must have write permissions in the file system directory in which the compound file is created. If STGM_TRANSACTED is not specified, and STGM_CREATE is specified, an existing file with the same name is destroyed before creating the new file.
StgCreateDocfile can be used to create a temporary compound file by passing a NULL value for the pwcsName parameter. However, these files are temporary only in the sense that they have a system-provided unique name – likely one that is meaningless to the user. The caller is responsible for deleting the temporary file when finished with it, unless STGM_DELETEONRELEASE was specified for the grfMode parameter.
Windows CE: For the access mode (grfMode), Windows CE supports the following flags:
STGM_DIRECT
STGM_TRANSACTED
STGM_SIMPLE
STGM_READ
STGM_WRITE
STGM_READWRITE
STGM_PRIORITY
STGM_DELETEONRELEASE
STGM_CREATE
STGM_CONVERT
STGM_FAILIFTHERE
STGM_NOSCRATCH
Passing into this function any invalid and, under some circumstances, NULL pointers will result in unexpected termination of the application. For more information about handling exceptions, see Programming Considerations.
Windows NT: Use version 3.1 or later.
Windows: Use Windows 95 or later.
Windows CE: Use version 2.0 or later.
Header: Declared in objbase.h.
Import Library: Included as a resource in ole32.dll.
StgCreateDocFileOnILockBytes ; StgCreateStorageEx, STGM