CComBSTR::WriteToStream
保存 m_str 成员入流。
HRESULT WriteToStream(
IStream* pStream
) throw( );
参数
- pStream
[out]一个指向 IStream 接口的指针。流。
返回值
标准 HRESULT 值。
备注
使用 ReadFromStream 功能,可以重新创建从流内容BSTR。
示例
//implementation of IDataObject::GetData()
STDMETHODIMP CMyDataObj::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
{
HRESULT hr = S_OK;
if (pformatetcIn->cfFormat == CF_TEXT && pformatetcIn->tymed == TYMED_ISTREAM)
{
IStream *pStm;
// Create an IStream from global memory
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStm);
if (FAILED(hr))
return hr;
// Initialize CComBSTR
CComBSTR bstrStr = OLESTR("Hello World");
// Serialize string into stream
// the length followed by actual string is serialized into stream
hr = bstrStr.WriteToStream(pStm);
// Pass the IStream pointer back through STGMEDIUM struct
pmedium->tymed = TYMED_ISTREAM;
pmedium->pstm = pStm;
pmedium->pUnkForRelease = NULL;
}
return hr;
}
要求
Header: atlbase.h