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. Problems with files

Problems with files

Scheduled Pinned Locked Moved C / C++ / MFC
help
9 Posts 6 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.
  • A Offline
    A Offline
    Archer282
    wrote on last edited by
    #1

    Ok, i just im making a binder and i am using the CreateFile(), ReadFile(), and WriteFile() functions now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Problem 1 As you should be able to guess im going to split the output by a string (no problem since i already wrote a function for that) but if im reading in segments then well you know it could cut into that string im splitting by Problem 2 SetFilePointer doesnt seem to be working for me if i could get this to work i have an idea that m might (i stress might) solve my problems

    J D M A 4 Replies Last reply
    0
    • A Archer282

      Ok, i just im making a binder and i am using the CreateFile(), ReadFile(), and WriteFile() functions now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Problem 1 As you should be able to guess im going to split the output by a string (no problem since i already wrote a function for that) but if im reading in segments then well you know it could cut into that string im splitting by Problem 2 SetFilePointer doesnt seem to be working for me if i could get this to work i have an idea that m might (i stress might) solve my problems

      J Offline
      J Offline
      Jaime Stuardo
      wrote on last edited by
      #2

      Didn't the third parameter of ReadFile work (nNumberOfBytesToRead)? Jaime

      A 1 Reply Last reply
      0
      • J Jaime Stuardo

        Didn't the third parameter of ReadFile work (nNumberOfBytesToRead)? Jaime

        A Offline
        A Offline
        Archer282
        wrote on last edited by
        #3

        Yes the third parameter of ReadFile has alwase worked. i am sorry but i dont really see what that has to do with either of my problems

        1 Reply Last reply
        0
        • A Archer282

          Ok, i just im making a binder and i am using the CreateFile(), ReadFile(), and WriteFile() functions now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Problem 1 As you should be able to guess im going to split the output by a string (no problem since i already wrote a function for that) but if im reading in segments then well you know it could cut into that string im splitting by Problem 2 SetFilePointer doesnt seem to be working for me if i could get this to work i have an idea that m might (i stress might) solve my problems

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

          »Archer282« wrote: now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Sure you can. I've used these functions before to read in a file 10x larger than that. No problem.


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          1 Reply Last reply
          0
          • A Archer282

            Ok, i just im making a binder and i am using the CreateFile(), ReadFile(), and WriteFile() functions now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Problem 1 As you should be able to guess im going to split the output by a string (no problem since i already wrote a function for that) but if im reading in segments then well you know it could cut into that string im splitting by Problem 2 SetFilePointer doesnt seem to be working for me if i could get this to work i have an idea that m might (i stress might) solve my problems

            M Offline
            M Offline
            Michael P Butler
            wrote on last edited by
            #5

            »Archer282« wrote: now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Really. I've read and written larger files in the past. What problems did you encounter? Michael CP Blog [^]

            A 1 Reply Last reply
            0
            • M Michael P Butler

              »Archer282« wrote: now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Really. I've read and written larger files in the past. What problems did you encounter? Michael CP Blog [^]

              A Offline
              A Offline
              Archer282
              wrote on last edited by
              #6

              well at first i just read all of it into one buffer i defined it like so char *szBuffer; and then wrote all of it right after reading everytime i would get the blue screen of death then if i returned to windows it would be locked up i looked at an example on MSDN which read and wrote the data in segments, i have had success doing it this way (no problems, except for the ones i mentioned) note: when i did this in segments i defined my buffer like char szBuffer[1024]; could this have been a problem? if it will help i clean up and post the old code that was wasnt working

              A 1 Reply Last reply
              0
              • A Archer282

                Ok, i just im making a binder and i am using the CreateFile(), ReadFile(), and WriteFile() functions now it took me long enough to figure out you cant read 28KB file into a buffer and write it all at once Problem 1 As you should be able to guess im going to split the output by a string (no problem since i already wrote a function for that) but if im reading in segments then well you know it could cut into that string im splitting by Problem 2 SetFilePointer doesnt seem to be working for me if i could get this to work i have an idea that m might (i stress might) solve my problems

                A Offline
                A Offline
                Archer282
                wrote on last edited by
                #7

                Funny how right when i go and ask for help my problem seem to be solved before i get an answer I kinda reverted my code to the way it was when i gettting the bsod and now it seems to be working just fine and i manged to get SetFilePointer() to go to the end but i had to use GetFileSize() Logically you would think you could go to the end by doing SetFilePointer( hFile, 0, NULL, FILE_END ); but i cant it get it to work doing that infact i cant even get it to go anywhere from FILE_END just occured to me could that be becuase i only used GENERIC_WRITE access?

                D 1 Reply Last reply
                0
                • A Archer282

                  well at first i just read all of it into one buffer i defined it like so char *szBuffer; and then wrote all of it right after reading everytime i would get the blue screen of death then if i returned to windows it would be locked up i looked at an example on MSDN which read and wrote the data in segments, i have had success doing it this way (no problems, except for the ones i mentioned) note: when i did this in segments i defined my buffer like char szBuffer[1024]; could this have been a problem? if it will help i clean up and post the old code that was wasnt working

                  A Offline
                  A Offline
                  avenger_sb25
                  wrote on last edited by
                  #8

                  >>well at first i just read all of it into one buffer. i defined it like so >>char *szBuffer; Well Mr. Hotshot, are you allocating memory for szBuffer ??? before using it with your file-handling-functions.... IF NO.... god help you X| . If yes... sorry. USE malloc or new to alllocate appropriate amount of memory. >>note: when i did this in segments i defined my buffer like >>char szBuffer[1024]; look closely... here you alocate the buffer's size to be 1024 bytes. BUT in char* szBuffer.... YOU MAY NOT BE ALLOCATING ANY MEMORY and the 'BLUE SCREEN' loves programmers like you. ;P .... i hope i helped;) ...Avenger


                  Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

                  1 Reply Last reply
                  0
                  • A Archer282

                    Funny how right when i go and ask for help my problem seem to be solved before i get an answer I kinda reverted my code to the way it was when i gettting the bsod and now it seems to be working just fine and i manged to get SetFilePointer() to go to the end but i had to use GetFileSize() Logically you would think you could go to the end by doing SetFilePointer( hFile, 0, NULL, FILE_END ); but i cant it get it to work doing that infact i cant even get it to go anywhere from FILE_END just occured to me could that be becuase i only used GENERIC_WRITE access?

                    D Offline
                    D Offline
                    darkbyte
                    wrote on last edited by
                    #9

                    Well, here's an idea to stop all those kind helping people from answering for nothing: :D Once you realize you solved your problem, you could edit your original post and change its title, appending "<--solved" to it. This would also have the added advantage of giving a clue to people having the same kind of question that they might find their answer in that thread. Anyone agrees with me ?

                    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