This sample code below demonstrates using CImage (from ATLImage.h) to load a file based image, save it to a stream, and create a COM picture interface which can be the return value in an OLE automation property.
The crazy thing is that OleLoadPicture fails with an error code indicating a corrupted file format. However, I am able to demonstrate in the error condition that the stream can again be loaded in a second CImage and saved back to disk. Comparison of the two file based bitmaps shows them to be identical.
It is a confounding problem as this seems the best way to pass image data around in COM.
Can anyone think of why this fails? My only suspicion is that the saved BMP somehow does not conform to some standard but then again I can look at it with any image viewer
IStream * pImageStream = ImageStream.GetStream();
if (pImageStream && SUCCEEDED(ImageDIB.Save(pImageStream,Gdiplus::ImageFormatBMP)))
HRESULT hr = OleLoadPicture(pImageStream,(LONG)ImageStream.GetLength(),FALSE,IID_IPicture,(LPVOID *)&Picture);