Share via


CComBSTR::ReadFromStream

Sets the m_str member to the BSTR contained in the specified stream.

HRESULT ReadFromStream(
   IStream* pStream 
) throw( );

Parameters

  • pStream
    [in] A pointer to the IStream interface on the stream containing the data.

Return Value

A standard HRESULT value.

Remarks

ReadToStream requires the contents of the stream at the current position to be compatible with the data format written out by a call to WriteToStream.

Example

IDataObject* pDataObj;

// Fill in the FORMATETC struct to retrieve desired format 
// from clipboard
FORMATETC formatetcIn = {CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_ISTREAM};
STGMEDIUM medium;
ZeroMemory(&medium, sizeof(STGMEDIUM));

// Get IDataObject from clipboard
HRESULT hr = ::OleGetClipboard(&pDataObj);

// Retrieve data from clipboard
hr = pDataObj->GetData(&formatetcIn, &medium);

if (SUCCEEDED(hr) && medium.tymed == TYMED_ISTREAM)
{
   CComBSTR bstrStr;
   // Get BSTR out of the stream
   hr = bstrStr.ReadFromStream(medium.pstm);

   //release the stream
   ::ReleaseStgMedium(&medium);
}

Requirements

Header: atlbase.h

See Also

Reference

CComBSTR Class

Other Resources

CComBSTR Members