描述:
MFC 中把_bstr_t 或者 CString 传入下面函数.
LoadFromStream(IUnknown * Stream );//IUnknown * Stream
// 从数据留读取数据..
解决方案1:
BOOL COleStreamFile::CreateMemoryStream
virtual void CFile::Write( const void* lpBuf, UINT nCount );
IStream* COleStreamFile::GetStream
创建一个流读入数据就可以了!
eg
cout<<"Test IStorage!"<<endl;
IStorage *stg = 0;
IStream *stream = 0;
IStream *stream1 = 0;
HRESULT re = ::StgOpenStorage(L"c:\\my",NULL, STGM_SHARE_EXCLUSIVE | STGM_DIRECT | STGM_READWRITE,NULL,0,&stg);
if(FAILED(re))
{
std::cout<<"the file is a structured storage file";
}
else
{
re = stg->CreateStream(L"mystream",STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,0,0,&stream1);
if(SUCCEEDED(re))
{
stream1->Release ();
}
re = stg->OpenStream(L"mystream",NULL,STGM_READWRITE | STGM_DIRECT | STGM_SHARE_EXCLUSIVE,0,&stream);
if(FAILED(re))
{
::GetLastError();
}
ULONG cb;
re = stream->Write(L"Hello",strlen("Hello"),&cb);
char s[256];
unsigned short olestr[256];
re = stream->Read(olestr,255,&cb);
wcstombs(s,olestr,255);
cout<<s<<endl;
stream->Release();
}
stg->Release();