Επεξεργασία

Κοινή χρήση μέσω


SHCreateStreamOnFileEx function (shlwapi.h)

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

Syntax

LWSTDAPI SHCreateStreamOnFileEx(
  [in]           LPCWSTR pszFile,
  [in]           DWORD   grfMode,
  [in]           DWORD   dwAttributes,
  [in]           BOOL    fCreate,
  [in, optional] IStream *pstmTemplate,
  [out]          IStream **ppstm
);

Parameters

[in] pszFile

Type: LPCWSTR

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

[in] grfMode

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.

[in] dwAttributes

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.

[in] fCreate

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.

[in, optional] pstmTemplate

Type: IStream*

Reserved.

[out] ppstm

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.

grfMode fCreate File exists? Behavior
STGM_CREATE Ignored Yes The file is recreated.
STGM_CREATE Ignored No The file is created.
STGM_FAILIFTHERE FALSE Yes The file is opened.
STGM_FAILIFTHERE FALSE No The call fails.
STGM_FAILIFTHERE TRUE Yes The call fails.
STGM_FAILIFTHERE TRUE No The file is created.

Requirements

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 6.0 or later)