Thread: Loading files with a function call

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Edit: Okay, so I had the wrong pointer type in the struct. I forgot it's ->. I also had "BMPdata" instead of "BMPData" which, strangely enough, messed things up (must be case sensitive). Now I'm getting an "unhandled exception" error and it asks me if I want to look at the disassembly. I look at it but have no idea what any of that is. What is causing this to happen?

    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....
    Last edited by ulillillia; 04-10-2007 at 08:46 PM. Reason: Resolved the issue

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 07:51 AM