I am having problems with copying data to an offset.
To start I'll show you my code and explain what I am doing
ifstream file ("c:\\test.bmp",ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size=file.tellg();
memblock=new char[size];
file.seekg(0,ios::beg);
file.read(memblock,size);
file.close();
}
else
{
MessageBox(NULL,"Unable to open file","Unable to open file",NULL);
SetFocus(hWnd);
PostQuitMessage(0);
return 0;
}
// Stage 1
memset(&bmfh,0,sizeof(BITMAPFILEHEADER));
memcpy(&bmfh,memblock,sizeof(BITMAPFILEHEADER));
// Stage 2
memset(&lpbi,0,sizeof(BITMAPINFOHEADER));
memcpy(&lpbi,&memblock+sizeof(BITMAPFILEHEADER),sizeof(BITMAPINFOHEADER));
char szBuffer[10];
MessageBox(NULL,itoa(lpbi->bmiHeader.biCompression,szBuffer,10),"",NULL);
I am loading a bitmap into memory (with a header (BITMAPFILEHEADER) of 14 bytes).
The header is copied from 'memblock' to the 'bmfh' struct. At this point, with a bit of debugging, the results are correct.
I am then trying to copy the next 40 bytes into an LPBITMAPINFO struct from 'memblock + 14 (the size of BITMAPFILEHEADER).
But from this point the results are corrupted. Where 'lpbi->bmiHeader.biCompression' should be set to 0, the result is random every time.
Is the way I am using memcpy wrong?
Any help would be awesome as I am pretty 'debugged' out
[Edit]
The bitmap I am using is correct and had a 14 byte BITMAPFILEHEADER, has 40 bytes of LPBITMAPINFO, and is data after that point.
[/edit]