Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why won't this simple thing work?

Why won't this simple thing work?

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsgame-devdata-structuresquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pizzaman
    wrote on last edited by
    #1

    Hello, I am trying to load up bitmaps onto DirectX surfaces. Well anyway... this is the function prototype: Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename); so I tried to read the bitmap names from a file with the following: infile.open("TileBitmap.dat"); int value = 0; char tempFilename[256] = {0}; while(infile) { infile >> value; //get the bitmap number infile.getline(tempFilename, 256); //get the filename.bmp MessageBox(main_window_handle, tempFilename, "Test", MB_OK); if (!(Load_Bitmap_File(&bit, tempFilename))) { infile.close(); //close the file return 0; //and report error } LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT); //if all good, load it into surface array } infile.close(); and the darn thing fails with the Load_Bitmap_File notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap. So I tried... manual initialization char tempFilename[256] = "filename.bmp" Load_Bitmap_File(&bit, tempFilename); and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks! -Pizzaman -It's like blowing up an abortion center because you are pro life.

    Z D 2 Replies Last reply
    0
    • P Pizzaman

      Hello, I am trying to load up bitmaps onto DirectX surfaces. Well anyway... this is the function prototype: Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename); so I tried to read the bitmap names from a file with the following: infile.open("TileBitmap.dat"); int value = 0; char tempFilename[256] = {0}; while(infile) { infile >> value; //get the bitmap number infile.getline(tempFilename, 256); //get the filename.bmp MessageBox(main_window_handle, tempFilename, "Test", MB_OK); if (!(Load_Bitmap_File(&bit, tempFilename))) { infile.close(); //close the file return 0; //and report error } LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT); //if all good, load it into surface array } infile.close(); and the darn thing fails with the Load_Bitmap_File notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap. So I tried... manual initialization char tempFilename[256] = "filename.bmp" Load_Bitmap_File(&bit, tempFilename); and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks! -Pizzaman -It's like blowing up an abortion center because you are pro life.

      Z Offline
      Z Offline
      ZoogieZork
      wrote on last edited by
      #2

      Is it possible that tempFilename contains an embedded LF or CRLF at the end of the string? That would explain why it would display fine in the message box, but would still bomb out. Stepping through in a debugger would be advised :) - Mike

      P 1 Reply Last reply
      0
      • Z ZoogieZork

        Is it possible that tempFilename contains an embedded LF or CRLF at the end of the string? That would explain why it would display fine in the message box, but would still bomb out. Stepping through in a debugger would be advised :) - Mike

        P Offline
        P Offline
        Pizzaman
        wrote on last edited by
        #3

        Yes, that is most likely the case, because the file is setup as... 0 grass1.bmp 1 grass2.bmp 2 grass3.bmp . . . -Pizzaman -It's like blowing up an abortion center because you are pro life.

        1 Reply Last reply
        0
        • P Pizzaman

          Hello, I am trying to load up bitmaps onto DirectX surfaces. Well anyway... this is the function prototype: Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename); so I tried to read the bitmap names from a file with the following: infile.open("TileBitmap.dat"); int value = 0; char tempFilename[256] = {0}; while(infile) { infile >> value; //get the bitmap number infile.getline(tempFilename, 256); //get the filename.bmp MessageBox(main_window_handle, tempFilename, "Test", MB_OK); if (!(Load_Bitmap_File(&bit, tempFilename))) { infile.close(); //close the file return 0; //and report error } LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT); //if all good, load it into surface array } infile.close(); and the darn thing fails with the Load_Bitmap_File notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap. So I tried... manual initialization char tempFilename[256] = "filename.bmp" Load_Bitmap_File(&bit, tempFilename); and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks! -Pizzaman -It's like blowing up an abortion center because you are pro life.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          When using infile.getline(tempFilename, 256);, could there be extra (hidden) characters in tempFilename? MessageBox() is not exactly the best choice to use for looking at data. Using both methods you described, put a breakpint on the Load_Bitmap_File() line and look at tempFilename in the debugger at that point. See if there are any differences between the two.


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups