Code:
char LoadFile(char FileName[64], BITMAPINFOHEADER *BMPInfo, char *BMPData) // accepts a string as a parameter
{
char BasePath[128]; // the base path, that of which started from
char FullFileName[192]; // the full path combining the base path and the parameter
strcpy(BasePath, "C:\\My Documents\\My programs\\"); // get the obvious base path first
sprintf(FullFileName, "%s%s", BasePath, FileName); // combine the base path and file name
FileHandle = fopen(FullFileName, "rb"); // read the source file to display, binary mode
if (FileHandle == 0) // if the file can't be found
{
return 1; // indicates an error occurred
}
fseek(FileHandle, 14, SEEK_SET); // skip the basic file header data but read from the info header
fread(&BMPInfo->biSize, 4, 1, FileHandle); // bytes 0E through 11
fread(&BMPInfo->biWidth, 4, 1, FileHandle); // 12 through 15
fread(&BMPInfo->biHeight, 4, 1, FileHandle); // 16 through 19
fread(&BMPInfo->biPlanes, 2, 1, FileHandle); // 1A and 1B
fread(&BMPInfo->biBitCount, 2, 1, FileHandle); // 1C and 1D
fread(&BMPInfo->biCompression, 4, 1, FileHandle); // 1E through 21
fread(&BMPInfo->biSizeImage, 4, 1, FileHandle); // 22 through 25
fread(&BMPInfo->biXPelsPerMeter, 4, 1, FileHandle); // 26 through 29
fread(&BMPInfo->biYPelsPerMeter, 4, 1, FileHandle); // 2A through 2D
fread(&BMPInfo->biClrUsed, 4, 1, FileHandle); // 2E through 31
fread(&BMPInfo->biClrImportant, 4, 1, FileHandle); // 32 through 35
fread(BMPData, 1, BMPInfo->biSizeImage, FileHandle); // read the main image data // bytes 36 and onward
fclose(FileHandle); // close the file releasing the handle
return 0;
}
LoadFile("ulillilliacity.bmp", &BMPHead, &TestImageData); // function called
Edit: Never mind, I fixed the problem in full. I had "&BMPData" instead of "BMPData". I seem to need more practice with pointers....