64,654
社区成员
发帖
与我相关
我的任务
分享
IStream * pIStream = NULL;
CLSID encoderClisid;
GetEncoderClsid(L"image/bmp",&encoderClisid);
image.save(pIStream,&encoderClis,NULL);
// 程序执行不对
Status MakeCompoundFile()
{
IStorage* pIStorage = NULL;
IStream* pIStream1 = NULL;
IStream* pIStream2 = NULL;
HRESULT hr;
Status stat = Ok;
// Create two Image objects from existing files.
Image image1(L"Crayons.jpg");
Image image2(L"Mosaic.png");
hr = CoInitialize(NULL);
if(FAILED(hr))
goto Exit;
// Create a compound file object, and get
// a pointer to its IStorage interface.
hr = StgCreateDocfile(
L"CompoundFile.cmp",
STGM_READWRITE|STGM_CREATE|STGM_SHARE_EXCLUSIVE,
0,
&pIStorage);
if(FAILED(hr))
goto Exit;
// Create a stream in the compound file.
hr = pIStorage->CreateStream(
L"StreamImage1",
STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
0,
0,
&pIStream1);
if(FAILED(hr))
goto Exit;
// Create a second stream in the compound file.
hr = pIStorage->CreateStream(
L"StreamImage2",
STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
0,
0,
&pIStream2);
if(FAILED(hr))
goto Exit;
// Get the class identifier for the JPEG encoder.
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid);
// Get the class identifier for the PNG encoder.
CLSID pngClsid;
GetEncoderClsid(L"image/png", &pngClsid);
// Save image1 as a stream in the compound file.
stat = image1.Save(pIStream1, &jpgClsid);
if(stat != Ok)
goto Exit;
// Save image2 as a stream in the compound file.
stat = image2.Save(pIStream2, &pngClsid);
Exit:
if(pIStream1)
pIStream1->Release();
if(pIStream2)
pIStream2->Release();
if(pIStorage)
pIStorage->Release();
if(stat != Ok || FAILED(hr))
return GenericError;
return Ok;
}