Saving Bitmap from Clipboard to File Error
- by Vanwaril
I'm using OLEDropTarget to get dropped content. It works fine with text. However, I'm not able to figure out how to get bitmaps from CF_BITMAP type data objects and save them to file. My code:
HGLOBAL hg = pDataObject->GetGlobalData(CF_BITMAP);
if (NULL == hg)
{
return FALSE;
}
HBITMAP pData = (HBITMAP)GlobalLock(hg);
if(pData == NULL)
return false;
HBITMAP bmp;
::GetObject(pData,sizeof(HBITMAP),&bmp);
CImage cnn;
cnn.Attach(bmp);
cnn.Save(L"here.bmp",Gdiplus::ImageFormatBMP);
I get an error on the Attach, but when debugging I noticed that the GetObject doesn't make a copy into the second HBITMAP.