Windows GetDIBits Call Not Working - I'm desperate - please help - I'm begging!
Hi there,
I have a nightmare with the GetDIBits call. It is working 95% of the time, but occasionally fails inexplicably. I say inexplicably, because it returns zero (fail result) but the Windows GetLastError() call says there was no error afterwards.
Can anyone help? I have put some of my code below, where 'src' is the HBITMAP. Is possible that HBITMAP could be being used by another area of windows at the time? If so, how can I release it?
Thanks
Code:
HDC hdc = 0;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// Make temporary compatible device
hdc = CreateCompatibleDC(0);
// Get dimensions first
GetDIBits(hdc, (HBITMAP)src, 0, 0, 0, &bmi, DIB_RGB_COLORS);
// We always want positive height (bottom up bmp)
bmi.bmiHeader.biHeight = abs(bmi.bmiHeader.biHeight);
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
// Create memory
data = new char[bmi.bmiHeader.biSizeImage];
if (GetDIBits(hdc, (HBITMAP)src, 0, bmi.bmiHeader.biHeight, data,
&bmi, DIB_RGB_COLORS) == 0)
{
FAILS HERE
with GetLastError == 0 (OK?)
}