I am trying to write a char array to a bitmap in c++. I (think) i know what values I need in my file header and bitmap info header, and i have looked at some examples but I cant seem to solve this problem (i'm sure its something stupid)
In the code below, writing the file header is fine. I am writing the info header in exactly the same way, but it comes up with:
error C2227: left of '->biSize' must point to class/struct/union/generic type
1> type is 'LPBITMAPINFOHEADER *'
for the whole header, this made me think to use lpbi->biSize instead of lpbi.biSize, but then i get a runtime error: "The variable 'lpbi' is being used without being initialized." But I'm not sure how to initialize it, and why doesn't it do that for the BITMAPFILEHEADER?
Thanks for any help
HANDLE fh; DWORD nWritten; BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; // Fill in the fields of the file header hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM" hdr.bfSize = sizeof(hdr) + sizeof(BITMAPINFOHEADER) + pBufferSize; hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; hdr.bfOffBits = sizeof(hdr) + sizeof(BITMAPINFOHEADER); //Fill in the fields of the info header lpbi.biSize = 40; lpbi.biWidth = width; lpbi.biHeight = height; lpbi.biPlanes = 1; lpbi.biBitCount = 24; lpbi.biSizeImage = pBufferSize; lpbi.biCompression = 0; lpbi.biXPelsPerMeter = 0; lpbi.biYPelsPerMeter = 0; lpbi.biClrUsed = 0; lpbi.biClrImportant = 0; fh = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(fh, &hdr, sizeof(hdr), &nWritten, NULL); WriteFile(fh, lpbi, sizeof(BITMAPINFOHEADER), &nWritten, NULL); WriteFile(fh, pBuffer, pBufferSize, &nWritten, NULL); CloseHandle(fh);
Edited 6 Years Ago by hanvyj: put language is c++