My code currently looks like this:-
Code:
HBITMAP ReadFrame(unsigned char *Image, unsigned char Palette[3][256], HPALETTE hPalReturn)
{
int i;
LPBITMAPINFO lpbmpinfo = (LPBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
HBITMAP hBitmap;
HDC hScreenDC;
HPALETTE hPal, hOldPal;
for(i=0;i<256;i++)
{
lpbmpinfo->bmiColors[i].rgbRed = Palette[0][i];
lpbmpinfo->bmiColors[i].rgbGreen = Palette[1][i];
lpbmpinfo->bmiColors[i].rgbBlue = Palette[2][i];
lpbmpinfo->bmiColors[i].rgbReserved = 0;
}
lpbmpinfo->bmiHeader.biSize = sizeof(lpbmpinfo->bmiHeader);
lpbmpinfo->bmiHeader.biBitCount = 8;
lpbmpinfo->bmiHeader.biCompression = BI_RGB;
lpbmpinfo->bmiHeader.biHeight = -240;
lpbmpinfo->bmiHeader.biPlanes = 1;
lpbmpinfo->bmiHeader.biWidth = 320;
hScreenDC = GetDC(NULL);
hPal = CreateDIBPalette(lpbmpinfo);
hOldPal = SelectPalette(hScreenDC, hPal, FALSE);
RealizePalette(hScreenDC);
hBitmap = CreateDIBitmap(hScreenDC, &lpbmpinfo->bmiHeader, CBM_INIT, Image, lpbmpinfo, DIB_RGB_COLORS);
SelectPalette(hScreenDC, hOldPal, FALSE);
ReleaseDC(NULL, hScreenDC);
hPalReturn = hPal;
return hBitmap;
}
CreateDIBPalette simply makes a GDI palette object from the palette stored in lpbmpinfo.
However, when I run this, CreateDIBitmap does not appear to work and an Access Violation error occurs. I'm porting this code from VB, and it works there (although not without modification to the BITMAPINFO struct to have 256 entries (as there is no pointer support)). I'm stumped...