🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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

Started by
13 comments, last by ThaUnknownProgga 24 years, 6 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); 


Advertisement
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
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