I'm developping a thumbnail creator as a shell extension.
To do that, I choosed to implement interface IExtractImage.
My dll is loaded and correctly called, but, the thumbnail is always black, instead of being red.
What am I missing?
class MyShellPreview : public IExtractImage, IPersistFile
// set by IExtractImage::GetLocation
SIZE m_size;
IFACEMETHODIMP Extract(HBITMAP *phBmpImage)
{
size_t size = m_size.cx * m_size.cy * 3;
// alloc buffer
BYTE *buffer = (BYTE*)malloc(size);
// fill buffer
for (k = i = 0; i < m_size.cx; ++i)
{
for (j = 0; j < m_size.cy; ++j, ++k)
{
buffer[k] = 128;
buffer[k+1] = 0;
buffer[k+2] = 0;
}
}
*phBmpImage = CreateBitmap(m_size.cx, m_size.cy, 3, 8, buffer);
free(buffer);
return S_OK;
}
};
I know that for performance reason, I should use CreateCompatibleBitmap and SetDIBits, but I'm not sure from where I should get an HDC.
CreateBitmapshould be 1. Aside from that, I strongly suggest creating 32-bpp bitmaps, since that's what all modern graphics hardware uses internally. It will save the need to do conversions and make your life simpler, too. Remember that in Windows, because it's little-endian, the BGRA format is used. - Cody GrayCreateBitmap(m_size.cx, m_size.cy, 1, 8, buffer)without success, I just try withCreateBitmap(m_size.cx, m_size.cy, 1, 32, buffer), it seems to be much better... - Mathieuk, so you aren't filling or manipulating anything other than the first pixel, regardless of what the comments above say! You will need to fix all these issues at the same time to make this work. - andlabs