There is an example of downloading images from a file (checked, downloads bmp, jpg, gif, etc.). How can I download HBIΠ’MAP from memory?
For the OleCreateFromData function, I can't figure out how to create an IDataObject from a piece (I think that it is the answer). There is an example for SO with GdiPlus, but there it is not clear how to translate it into HBITMAP. LoadBitmapIndirect - loads only bitmaps of a certain configuration (does not fit). OleCreateFromFile - loads from a file - does not fit.
There is more, you can create an object through CoCreateInstance , and download IStorage through IStorage . Here the strange problem in borand delphi is a piece of code , but for some reason it gives an error:
char[] gif={0x47,0x49,0x46,0x38,0x39,0x61,0x0C,0x00,0x0C,0x00,0x80,0xFF,0x00,0x9C,0x00,0x00 ,0xC0,0xC0,0xC0,0x21,0xF9,0x04,0x01,0x00,0x00,0x01,0x00,0x2C,0x00,0x00,0x00,0x00 ,0x0C,0x00,0x0C,0x00,0x00,0x02,0x1B,0x8C,0x7F,0x80,0xA1,0x09,0xCD,0x9E,0x79,0x72 ,0xD2,0xBB,0x6E,0xCD,0x74,0x59,0x8C,0x68,0xDD,0xA7,0x68,0xD1,0x06,0x6E,0x96,0xC7,0x06,0x05,0x00,0x3B}; int dwBytes = sizeof(gif); HGLOBAL hStorage = ::GlobalAlloc(GMEM_SHARE|GMEM_MOVEABLE, dwBytes); if (hStorage == NULL) AfxThrowMemoryException(); LPVOID lpBuf = ::GlobalLock(hStorage); ASSERT(lpBuf != NULL); memcpy(lpBuf,gif, dwBytes); ::GlobalUnlock(hStorage); // throw exception in case of partial object SCODE sc = CreateILockBytesOnHGlobal(hStorage, TRUE, &m_lpLockBytes); if (sc != S_OK){::GlobalFree(hStorage);AfxThrowOleException(sc);} sc = ::StgOpenStorageOnILockBytes(m_lpLockBytes, NULL, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, NULL, 0, &m_lpStorage); StgOpenStorageOnILockBytes gives either an error 800300FB ( invalid header ), or 800300FF ( invalid flag ), or 0x80030050 ( file not exist ). The error depends on the flags. Is it possible to load a picture somehow differently into the CLSID_Picture_DIB object?
Here is an example of how you can load from a file (it loads gif, that is, OLE still knows how to load pictures):
HANDLE Handle; // ΠΠ°Π³ΡΡΠ·ΠΊΠ° Π² Handle Π±ΠΈΡΠΌΠ°ΠΏΠ° HRESULT LoadOLE(wchar_t* FileName){ HRESULT Result; tagFORMATETC fmt; tagSTGMEDIUM stg; ILockBytes *FLockBytes=0; IStorage *iStorage=0; IDataObject *Data=0; if ((Result =CreateILockBytesOnHGlobal(0, 1, &FLockBytes))!=0) return Result; if ((Result =StgCreateDocfileOnILockBytes(FLockBytes, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &iStorage))!=0){ FLockBytes->Release(); FLockBytes=0; return Result; }; fmt.cfFormat = CF_BITMAP; fmt.dwAspect=1; fmt.lindex=-1; fmt.ptd=0; fmt.tymed=2; Result =OleCreateFromFile(CLSID_Picture_Dib,FileName, IID_IDataObject,OLERENDER_NONE,&fmt,0,iStorage,(void**)&Data); if (Result==0) Result =OleRun(Data); if (Result==0) Result =Data->GetData(&fmt,&stg); if (Result==0) Handle = stg.hBitmap; if (Data) Data->Release(); Data=0; iStorage->Release(); iStorage=0; FLockBytes->Release(); FLockBytes=0; // return Result; // ΠΡΡΠΈΡΠΎΠ²ΠΊΠ° Handle Π±ΠΈΡΠΌΠ°ΠΏΠ° HDC dest = GetDC(0 /*ΠΠ΅ΡΠΊΡΠΈΠΏΡΠΎΡ ΠΎΠΊΠ½Π°*/); // Π΄ΠΎΠΏΡΡΡΠΈΠΌ ΠΌΠΎΠ½ΠΈΡΠΎΡ HDC dc = CreateCompatibleDC(0); SelectObject(dc,Handle); BitBlt(dest,x,y,xx,yy, dc,0,0,SRCCOPY); ReleaseDC( 0 /*ΠΠ΅ΡΠΊΡΠΈΠΏΡΠΎΡ ΠΎΠΊΠ½Π°*/, dest); } But the question remains open.