SHCreateStreamOnFileA function (shlwapi.h)

[SHCreateStreamOnFile is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use SHCreateStreamOnFileEx.]

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


LWSTDAPI SHCreateStreamOnFileA(
  [in]  LPCSTR  pszFile,
  [in]  DWORD   grfMode,
  [out] IStream **ppstm


[in] pszFile


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

[in] grfMode


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.

[out] ppstm

Type: IStream**

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

Return value


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


SHCreateStreamOnFileEx fully supports all STGM modes and allows the caller to specify file attributes if creating a new file.


The shlwapi.h header defines SHCreateStreamOnFile as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header shlwapi.h
Library Shlwapi.lib
DLL Shlwapi.dll (version 5.0 or later)