CComBSTR::ReadFromStream

HRESULT ReadFromStream( IStream* pStream );

Return Value

A standard HRESULT value.

Parameters

pStream

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

Remarks

Sets the m_str member to the BSTR contained in the specified stream. ReadToStream requires a previous call to WriteToStream.

Example

void CMyView::OnEditCopy()
{
   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);
   }

}

CComBSTR OverviewClass Members