0 out of 2 rated this helpful - Rate this topic

SHCreateStreamOnFileEx function

Applies to: desktop apps only

Opens or creates a file and retrieves a stream to read or write to that file.

Syntax

HRESULT SHCreateStreamOnFileEx(
  __in        LPCWSTR pszFile,
  __in        DWORD grfMode,
  __in        DWORD dwAttributes,
  __in        BOOL fCreate,
  __reserved  IStream *pstmTemplate,
  __out       IStream **ppstm
);

Parameters

pszFile [in]

Type: LPCWSTR

A pointer to a null-terminated string that specifies the file name.

grfMode [in]

Type: DWORD

One or more STGM values that are used to specify the file access mode and how the object that exposes the stream is created and deleted.

dwAttributes [in]

Type: DWORD

One or more flag values that specify file attributes in the case that a new file is created. For a complete list of possible values, see the dwFlagsAndAttributes parameter of the CreateFile function.

fCreate [in]

Type: BOOL

A BOOL value that helps specify, in conjunction with grfMode, how existing files should be treated when creating the stream. See Remarks for details.

pstmTemplate [in, optional]

Type: IStream*

Reserved.

ppstm [out]

Type: IStream**

Receives an IStream interface pointer for the stream associated with the file.

Return value

Type: HRESULT

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

The SHCreateStreamOnFileEx function extends the semantics of the STGM flags and produces the same effect as calling the CreateFile function.

The grfMode and fCreate parameters work together to specify how the function should behave with respect to existing files.

grfModefCreateFile exists?Behavior
STGM_CREATEIgnoredYesThe file is recreated.
STGM_CREATEIgnoredNoThe file is created.
STGM_FAILIFTHEREFALSEYesThe file is opened.
STGM_FAILIFTHEREFALSENoThe call fails.
STGM_FAILIFTHERETRUEYesThe call fails.
STGM_FAILIFTHERETRUENoThe file is created.

 

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 6.0 or later)

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Can't do OPEN_ALWAYS
There appears to be no combination of flags that is equivalent to "OPEN_ALWAYS", which means to create the file if it does not exist or to open the file if it does exist.
Additional defines
Don't forget to define correct _WIN32_IE,
as shlwapi.h defines:

#if (_WIN32_IE >= 0x0600)
LWSTDAPI SHCreateStreamOnFileEx(LPCWSTR pszFile, ...
#endif
Additional lib and header needed for vista/win2008
To use SHCreateStreamOnFileEx make sure to link in shlwapi.lib and include shlwapi.h.