• Advertisement
Sign in to follow this  

Custom resource file problems

This topic is 4683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I'm trying to open a custom resource file I made, usign these functions.
SDL_Surface *LoadBMPFromResource(char *resourcefilename, char *bitmapfilename)
{
	//Get the bitmap's buffer and size from the resource file
	int filesize = 0;
	char *buffer = GetBufferFromResource(resourcefilename, bitmapfilename, &filesize);
	
	//Load the buffer into a surface using RWops
	SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
	SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1);
	
	//Release the bitmap buffer memory
	free(buffer);
	
	//Were we able to load the bitmap?
	if (temp == NULL) 
	{
		printf("Unable to load bitmap: %s\n", SDL_GetError());
		exit(1);
	}
	
	//Convert the image to optimal display format
	SDL_Surface *image;
	image = SDL_DisplayFormat(temp);
	
	//Free the temporary surface
	SDL_FreeSurface(temp);
	
	//Return our loaded image
	return image;
}

char *GetBufferFromResource(char *resourcefilename, char *resourcename, int *filesize) 
{
	//Try to open the resource file in question
	int fd = open(resourcefilename, O_RDONLY);
	if (fd < 0) 
	{
		perror("Error opening resource file");
		exit(1);
	}
	
	//Make sure we're at the beginning of the file
	lseek(fd, 0, SEEK_SET);
	
	//Read the first INT, which will tell us how many files are in this resource
	int numfiles;
	read(fd, &numfiles, sizeof(int));
	
	//Get the pointers to the stored files
	int *filestart = (int *) malloc(numfiles);
	read(fd, filestart, sizeof(int) * numfiles);
	
	//Loop through the files, looking for the file in question
	int filenamesize;
	char *buffer;
	int i;
	for(i=0;i<numfiles;i++) 
	{
		char *filename;
		//Seek to the location
		lseek(fd, filestart, SEEK_SET);
		//Get the filesize value
		read(fd, filesize, sizeof(int));
		//Get the size of the filename string
		read(fd, &filenamesize, sizeof(int));
		//Size the buffer and read the filename
		filename = (char *) malloc(filenamesize + 1);
		read(fd, filename, filenamesize);
		//Remember to terminate the string properly!
		filename[filenamesize] = '\0';
		//Compare to the string we're looking for
		if (strcmp(filename, resourcename) == 0) 
		{
			//Get the contents of the file
			buffer = (char *) malloc(*filesize);
			read(fd, buffer, *filesize);
			free(filename);
			break;
		}
		//Free the filename buffer
		free(filename);
	}
	
	//Release memory
	free(filestart);
	
	//Close the resource file!
	close(fd);
	
	//Did we find the file within the resource that we were looking for?
	if (buffer == NULL) 
	{
		MessageBox(NULL, "This program has experienced an error and needs to shut down.", "ERROR", MB_OK);
		End(1);
	}
	
	//Return the buffer
	return buffer;
}


but get the errors
main.obj : error LNK2019: unresolved external symbol _close referenced in function "char * __cdecl GetBufferFromResource(char *,char *,int *)" (?GetBufferFromResource@@YAPADPAD0PAH@Z)
main.obj : error LNK2019: unresolved external symbol _read referenced in function "char * __cdecl GetBufferFromResource(char *,char *,int *)" (?GetBufferFromResource@@YAPADPAD0PAH@Z)
main.obj : error LNK2019: unresolved external symbol _lseek referenced in function "char * __cdecl GetBufferFromResource(char *,char *,int *)" (?GetBufferFromResource@@YAPADPAD0PAH@Z)
main.obj : error LNK2019: unresolved external symbol _open referenced in function "char * __cdecl GetBufferFromResource(char *,char *,int *)" (?GetBufferFromResource@@YAPADPAD0PAH@Z)

WHY!!!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement