This topic has not yet been rated - Rate this topic

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.

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.

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

}

Reference

CComBSTR Class

Other Resources

CComBSTR Members

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ