Advertisement

Getting a filename from a file, then opening....

Started by January 01, 2000 05:29 PM
13 comments, last by ThaUnknownProgga 24 years, 11 months ago
here it is in more context so you can see what it looks like and get a better feel for what im doing. in the file it has c:\games\textures\clouds.bmp listed as a texture for an object. that''s what im trying to get out and load.

void OpenTexture(char *fname){   HBITMAP hbmp;   BITMAP bm;   HDC SurfDC, BmpHdc;   hbmp = (HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION);   if(hbmp==NULL)		return FALSE;   //blah blah the rest then:   return TRUE;}  // so you know, hbmp is null, that is the part that fails.char *fname;fname = new char[fnamelength];for(int b=0; b<fnamelength; b++)   fname = fgetc(fp);fname[fnamelength] = ''\0'';  //also tried "NULL" so you knowOpenTexture(fname); 


here it is in more context so you can see what it looks like and get a better feel for what im doing. in the file it has c:\games\textures\clouds.bmp listed as a texture for an object. that''s what im trying to get out and load.

void OpenTexture(char *fname){   HBITMAP hbmp;   BITMAP bm;   HDC SurfDC, BmpHdc;   hbmp = (HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION);   if(hbmp==NULL)		return FALSE;   //blah blah the rest then:   return TRUE;}  // so you know, hbmp is null, that is the part that fails.char *fname;fname = new char[fnamelength];for(int a=0; a<fnamelength; a++)   fnamefname[fnamelength] = ''\0'';  //also tried "NULL" so you knowOpenTexture(fname); 


'' Target=_Blank>Link
Advertisement
sorry for the double post, the first one screwed up and put that link in too because i used a between brackets. i changed it to 'd'

here it is in more context so you can see what it looks like and get a better feel for what im doing. in the file it has c:\games\textures\clouds.bmp listed as a texture for an object. that's what im trying to get out and load.

void OpenTexture(char *fname){   HBITMAP hbmp;   BITMAP bm;   HDC SurfDC, BmpHdc;   hbmp = (HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE / LR_CREATEDIBSECTION);   if(hbmp==NULL)		return FALSE;   //blah blah the rest then:   return TRUE;}  // so you know, hbmp is null, that is the part that fails.char *fname;fname = new char[fnamelength];for(int d=0; d<fnamelength; d++)   fname[d] = fgetc(fp);fname[fnamelength] = '\0';  //also tried "NULL" so you knowOpenTexture(fname);  




Edited by - ThaUnknownProgga on 1/3/00 11:40:15 PM
fname[fnamelength] = ''\0'';

this should be

fname[fnamelength-1] = 0;

Remember, as the string starts at 0 it ends at (length-1). Writing to fname[fnamelength] is touching memory that you shouldnt be, though in this case it probably isn''t touching anything critical, and I doubt that it''s what is causing the problem. My next debugging suggestion would be to try running OpenTexture("whatever.bmp") instead of passing the char pointer, and see if that works.

Good luck

Starfall
the filename thing was correct because of how i set it up, but that second part led me to fix the problem. THANKS!!!

This topic is closed to new replies.

Advertisement