Export (0) Print
Expand All

CComBSTR::ReadFromStream

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

HRESULT ReadFromStream( 
   IStream* pStream  
) throw( );

pStream

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

A standard HRESULT value.

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.

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);
}

Header: atlbase.h

Show:
© 2014 Microsoft