Function and pointer troubles
For malloc to work, I need to know how much memory is needed. For convenience, since it's done a lot, I've put this into a function as a parameter. The function is to set the global variable for the memory usage then malloc the amount of memory needed. Trouble is, I'm always getting 0. Using the debugger, I'm seeing that it is reaching the line, but it's not being set, and thus malloc is allocating 0 bytes, causing problems.
The main essentials are these:
Code:
unsigned char *SkyBlueData; // data to malloc
unsigned int SkyBlueMemoryUsage; // memory used
LPVOID SkyBlueDataPointer;
BITMAPINFO SkyBlueMainInfo;
BITMAPINFOHEADER SkyBlueInfo;
LPBITMAPINFOHEADER SkyBlueInfoPointer;
HBITMAP SkyBlueBMPHandle;
The function declaration is this:
Code:
int LoadImageFile(const char FileName[64], int FileType, int LoadType, BITMAPINFOHEADER *BMPInfo, unsigned char *BMPData, int FogUsed, double ObjectScaling, unsigned int *BMPMemoryUsage, unsigned int Special)
This is the key area:
Code:
BMPMemoryUsage = BMPInfo->biSizeImage; // sets the memory usage
BMPData = malloc(BMPMemoryUsage);
fread(BMPData, 1, BMPMemoryUsage, FileHandle);
This is how the function is called, with other essentials:
Code:
SkyBlueInfoPointer = &SkyBlueInfo;
LoadImageFile("scenery\\SkyBlue.bmp", 1, 0, &SkyBlueInfo, &SkyBlueData, 0, 0.0, &SkyBlueMemoryUsage, 0);
SkyBlueDataPointer = &SkyBlueData;
I can't just set the specific variable in the function - it'll be the only one set. Basically, I want to pass the SkyBlueMemoryUsage variable to the function so it can get set int the function for malloc to work properly and to keep a log of the memory usage. In other words, I have a global variable, A, that want a function, B, to set within it with the variable to be changed, A, referenced in the function's parameters.