0 out of 1 rated this helpful - Rate this topic

SHCreateMemStream function

[This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions of Windows.]

Applies to: desktop apps only

Creates a memory stream using a similar process to CreateStreamOnHGlobal, but with less functionality.

Syntax

IStream* SHCreateMemStream(
  __in_opt  const BYTE *pInit,
  __in      UINT cbInit
);

Parameters

pInit [in, optional]

Type: const BYTE*

A pointer to a buffer of size cbInit. The contents of this buffer are used to set the initial contents of the memory stream. If this parameter is NULL, the returned memory stream does not have any initial content.

cbInit [in]

Type: UINT

The number of bytes in the buffer pointed to by pInit. If pInit is set to NULL, cbInit must be zero.

Return value

Type: IStream*

Returns a pointer to the created memory stream on success, or NULL otherwise. The function does not return the reason for a failure.

Remarks

Prior to Windows Vista, this function was not included in the public Shlwapi.h file, nor was it exported by name from Shlwapi.dll. To use it on earlier systems, you must call it directly from the Shlwapi.dll file as ordinal 12.

This function creates a memory stream. This is an implementation of the IStream interface that stores its contents in memory. SHCreateMemStream differs from CreateStreamOnHGlobal in the following ways.

  • Thread safety. The stream created by SHCreateMemStream is not thread-safe. The stream created by CreateStreamOnHGlobal is thread-safe.
  • Initial contents. SHCreateMemStream accepts the initial contents in the form of a buffer. CreateStreamOnHGlobal accepts the initial contents in the form of an HGLOBAL.
  • Access to contents. SHCreateMemStream does not allow direct access to the stream contents. CreateStreamOnHGlobal permits access through GetHGlobalFromStream.
  • Failure information. If SHCreateMemStream fails, there is no way to obtain the reason for failure. CreateStreamOnHGlobal returns an HRESULT.
  • Support for IStream::Clone. The stream created by SHCreateMemStream does not support IStream::Clone. The stream created by CreateStreamOnHGlobal does.

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP

Minimum supported server

Windows 2000 Server, Windows Server 2003

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 5.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
Another important difference between the stream returned by CreateStreamOnHGlobal
The stream returned by SHCreateMemStream will return S_FALSE if you attempt to read past the end of the buffer.  But The stream returned by CreateStreamOnHGlobal will return S_OK and set *pcbRead to 0.