Re: Don't know how to insert my data array in loadpicture()
Boki wrote:
I am modifing the LoadPic example, I want to load my byte
array, not the file pointer, could you please advice? I
don't wehre to insert or modify ....
Here's slightly changed example.
/////////////////////////////////////////
void LoadPictureFileI(int ilength)
{
// original buffer
LPVOID pvSourceData = ...
// get buffer size
DWORD dwBuffSize = ...
_ASSERTE(-1 != dwBuffSize);
LPVOID pvData = NULL;
// alloc memory based on buffer size
HGLOBAL hGlobal = GlobalAlloc(
GMEM_MOVEABLE, dwBuffSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
// copy buffer and store in global memory
CopyMemory(pvData, pvSourceData, dwBuffSize);
GlobalUnlock(hGlobal);
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(
hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE,
IID_IPicture, (LPVOID*)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
InvalidateRect(ghWnd, NULL, TRUE);
}
/////////////////////////////////////////