windows_programming_notes.nbk: Home | Index | Next Page: CREATESTRUCT | Previous Page: CreateSolidBrush


 CreateStreamOnHGlobal

The CreateStreamOnHGlobal function creates a stream object stored in global memory. The memory supports the OLE implementation of the IStream interface.

The returned stream object supports both reading and writing, is not transacted, and does not support locking.

    WINOLEAPI CreateStreamOnHGlobal(
      __in          HGLOBAL     hGlobal,
      __in          BOOL        fDeleteOnRelease,
      __out         LPSTREAM*   ppstm
    );

Parameters

Return Value

This function supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following.

Remarks

The initial contents of the stream are the current contents of the memory block provided in the hGlobal parameter. If the hGlobal parameter is NULL, this function internally allocates memory.

The current contents of the memory block are undisturbed by the creation of the new stream object. Thus, you can use this function to open an existing stream in memory.

The initial size of the stream is the size of the memory handle returned by the Microsoft Win32 GlobalSize function. Because of rounding, this is not necessarily the same size that was originally allocated for the handle. If the logical size of the stream is important, follow the call to this function with a call to the IStream::SetSize method.

After you have created the stream object with CreateStreamOnHGlobal, call GetHGlobalFromStream to retrieve the global memory handle associated with the stream object.

If the caller sets the fDeleteOnRelease parameter to FALSE, then the caller must also free the hGlobal after the final release. If the caller sets the fDeleteOnRelease parameter to TRUE, the final release will automatically free the hGlobal as shown in the following example code.

    if(pData->fDeleteOnRelease) {
	    Verify(0==GlobalFree(pData->hGlobal));
    }

Requirements


windows_programming_notes.nbk: Home | Index | Next Page: CREATESTRUCT | Previous Page: CreateSolidBrush


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time