I don't know what call the subject, but I have another question, a more basic one. I have a function that loads files into memory (BMPs and later TGAs), but need to have some parts as dynamic, based on parameters in a function.
The function works as I tested it, but what my problem is is with the "BMPHead" and "TestImageData" elements. What do I do to have parameters for this function to be able to set these. I call the function like this:Code:char LoadFile(char FileName[64]) // 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(&BMPHead.biSize, 4, 1, FileHandle); // bytes 0E through 11 fread(&BMPHead.biWidth, 4, 1, FileHandle); // 12 through 15 fread(&BMPHead.biHeight, 4, 1, FileHandle); // 16 through 19 fread(&BMPHead.biPlanes, 2, 1, FileHandle); // 1A and 1B fread(&BMPHead.biBitCount, 2, 1, FileHandle); // 1C and 1D fread(&BMPHead.biCompression, 4, 1, FileHandle); // 1E through 21 fread(&BMPHead.biSizeImage, 4, 1, FileHandle); // 22 through 25 fread(&BMPHead.biXPelsPerMeter, 4, 1, FileHandle); // 26 through 29 fread(&BMPHead.biYPelsPerMeter, 4, 1, FileHandle); // 2A through 2D fread(&BMPHead.biClrUsed, 4, 1, FileHandle); // 2E through 31 fread(&BMPHead.biClrImportant, 4, 1, FileHandle); // 32 through 35 fread(&TestImageData, 1, BMPHead.biSizeImage, FileHandle); // read the main image data // bytes 36 and onward fclose(FileHandle); // close the file releasing the handle return 0; // function succeeded }
if (LoadFile("mytestimage.bmp")) {// message box for showing load error}
If I had these particular pointers, structs, or whatever they are involved, I'd have the function called like this:
if (LoadFile("mytestimage.bmp", BMPHead, TestImageData) {// message box}
What changes do I need to make to get it to work like this? I know how to get the message box so I don't need any assistance with that.



LinkBack URL
About LinkBacks


