Hey all, I've been messing around with this for a while now but can't figure out why the call is failing. The section of code looks like this:
GetLastError is displaying Error Code 8: ERROR_NOT_ENOUGH_MEMORYCode:if(GetDIBits(hDC, *hBitmap, 0, BitmapInfo->bmiHeader.biHeight,
Pixels, BitmapInfo, DIB_RGB_COLORS) == 0)
{
printf("%ld ", GetLastError());
return NULL;
}
If I removed LR_CREATEDIBSECTION from my LoadImage() function, below, then I get Error Code 0: ERROR_SUCCESS (The operation completed successfully.) That's the best Error I guess I could hope for, but none the less, it's still an error.
This isn't very likely. So my guess is that I'm doing something horribly wrong and either it's interpretting it wrong, or I actually did something to waste all of my memory. Either way, I don't see where I'm going wrong.
hBitmap has been initialized with:
BitmapInfo has been initialized with:Code:hBitmap = (HBITMAP)LoadImage(NULL, FILE_PATH, IMAGE_BITMAP, 0, 0,
LR_DEFAULTCOLOR|LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);
And the code leading up to the GetLastError line is:Code:bool CompleteBitmapInfo(HBITMAP *hBitmap, BITMAPINFO *BitmapInfo)
{
BITMAP Bitmap;
if(GetObject(*hBitmap, sizeof(BITMAP), &Bitmap) == 0)
return false;
BitmapInfo->bmiHeader.biBitCount = Bitmap.bmBitsPixel;
BitmapInfo->bmiHeader.biClrImportant = 0;
BitmapInfo->bmiHeader.biClrUsed = 0;
BitmapInfo->bmiHeader.biCompression = BI_RGB;
BitmapInfo->bmiHeader.biHeight = Bitmap.bmHeight;
BitmapInfo->bmiHeader.biPlanes = Bitmap.bmPlanes;
BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo->bmiHeader.biSizeImage = 0;
BitmapInfo->bmiHeader.biWidth = Bitmap.bmWidth;
//BitmapInfo.bmiHeader.biXPelsPerMeter =
//BitmapInfo.bmiHeader.biYPelsPerMeter =
BitmapInfo->bmiColors->rgbRed = NULL;
BitmapInfo->bmiColors->rgbGreen = NULL;
BitmapInfo->bmiColors->rgbBlue = NULL;
BitmapInfo->bmiColors->rgbReserved = NULL;
return true;
}
Any thoughts on this would really be appreciatedCode:HDC hDC = GetDC(NULL);
if(hDC == NULL)
return NULL;
unsigned char *Pixels = (unsigned char *)malloc(BitmapInfo->bmiHeader.biWidth *
BitmapInfo->bmiHeader.biHeight * sizeof(unsigned char));
if(Pixels == NULL)
return NULL;
if(GetDIBits(...