JpegToBmp(HGLOBAL hJpeg, DWORD size) { IStream *lpStream = NULL; HRESULT hr; if (size <= 0 || hJpeg == NULL) return FALSE; do { // Create jpeg stream of the global memory hr = CreateStreamOnHGlobal(hJpeg, TRUE, &lpStream); if (FAILED(hr)) break;
// Try to load the jpeg to IPicture IPicture *lpPicTemp = NULL; hr = OleLoadPicture(lpStream, size, TRUE, IID_IPicture, (LPVOID*)&lpPicTemp); if (FAILED(hr)) break;
// Succeeded, release the old picture and assign the new one to m_lpPic. if (m_lpPic) m_lpPic->Release(); m_lpPic = lpPicTemp;
// Precache the size of the IPicture m_lpPic->get_Width(&m_hmWidth); m_lpPic->get_Height(&m_hmHeight); }while (FALSE); if (lpStream) lpStream->Release(); return SUCCEEDED(hr); }
{
IStream *lpStream = NULL;
HRESULT hr;
if (size <= 0 || hJpeg == NULL)
return FALSE;
do
{
// Create jpeg stream of the global memory
hr = CreateStreamOnHGlobal(hJpeg, TRUE, &lpStream);
if (FAILED(hr))
break;
// Try to load the jpeg to IPicture
IPicture *lpPicTemp = NULL;
hr = OleLoadPicture(lpStream, size, TRUE, IID_IPicture, (LPVOID*)&lpPicTemp);
if (FAILED(hr))
break;
// Succeeded, release the old picture and assign the new one to m_lpPic.
if (m_lpPic)
m_lpPic->Release();
m_lpPic = lpPicTemp;
// Precache the size of the IPicture
m_lpPic->get_Width(&m_hmWidth);
m_lpPic->get_Height(&m_hmHeight);
}while (FALSE);
if (lpStream)
lpStream->Release();
return SUCCEEDED(hr);
}