I'm just starting to work with c++(using Dev c++) and have ran into a problem. I was following a tutorial and copied and pasted this function into my program, there where some errors but I managed to fix them so it would compile. Now it silently crashes on this line:
Code:
RtlMoveMemory(Bits, pDIB + sizeof(BITMAPINFOHEADER), bih.biSizeImage);
I have provided the function below and have surrounded the crashing line with stars. I would really appreciate any help.
Code:
BOOL CreateFromPackedDIBPointer(LPBYTE pDIB, int iFrame, int framenumber)
{
if (pDIB!=NULL);
{
//Creates a full-color (no palette) DIB from a pointer to a
//full-color memory DIB
//get the BitmapInfoHeader
BITMAPINFOHEADER bih;
RtlMoveMemory(&bih.biSize, pDIB, sizeof(BITMAPINFOHEADER));
//now get the bitmap bits
if (bih.biSizeImage < 1)
{
return FALSE;
}
BYTE* Bits=new BYTE;
//*****************************************************************************************
RtlMoveMemory(Bits, pDIB + sizeof(BITMAPINFOHEADER), bih.biSizeImage);
//*****************************************************************************************
//and BitmapInfo variable-length UDT
BYTE memBitmapInfo[40];
RtlMoveMemory(memBitmapInfo, &bih, sizeof(bih));
BITMAPFILEHEADER bfh;
bfh.bfType=19778; //BM header
bfh.bfSize=55 + bih.biSizeImage;
bfh.bfReserved1=0;
bfh.bfReserved2=0;
bfh.bfOffBits=sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER); //54
FileName=("Frame-",(char)framenumber,".bmp");
FILE* fp=fopen(FileName, "wb");
if (fp!=NULL)
{
fwrite(&bfh, sizeof(bfh), 1, fp);
fwrite(&memBitmapInfo, sizeof(memBitmapInfo), 1, fp);
fwrite(Bits, bih.biSizeImage, 1, fp);
fclose(fp);
}
else
{
TRACE0(_T("Error writing the bitmap file"));
return FALSE;
}
delete [] Bits;
return TRUE;
}
}
Thanks for reading!