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. How CreateFile can fail???

How CreateFile can fail???

Scheduled Pinned Locked Moved C / C++ / MFC
questionbusiness
7 Posts 5 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.
  • D Offline
    D Offline
    Dimitris Vikeloudas
    wrote on last edited by
    #1

    I want to use CreateFile for creating of new files, overidding existing ones or just simply open them in various modes (depending on my applications' requirements). I know that when it fails it returns INVALID_HANDLE_VALUE and I have to use the GetLastError to find why. However, the GetLastError is a generic system function. Is anywhere any documentation about what errors can be the result of CreateFile. How do I know e.g. if I failed 'cause tried to create an existing file, tried to open an non-existing file, do not have enough disk space, do not have access to the parent directory, lost connection with a remote file store etc. A cross reference list function-possible failures would be usefull for any Win32 function (I am looking for it not only for the CreateFile). Anyone can point me to such documentation (books, web pages, etc) will be much appreciated. Life is a river with mist ahead...

    C RaviBeeR 3 Replies Last reply
    0
    • D Dimitris Vikeloudas

      I want to use CreateFile for creating of new files, overidding existing ones or just simply open them in various modes (depending on my applications' requirements). I know that when it fails it returns INVALID_HANDLE_VALUE and I have to use the GetLastError to find why. However, the GetLastError is a generic system function. Is anywhere any documentation about what errors can be the result of CreateFile. How do I know e.g. if I failed 'cause tried to create an existing file, tried to open an non-existing file, do not have enough disk space, do not have access to the parent directory, lost connection with a remote file store etc. A cross reference list function-possible failures would be usefull for any Win32 function (I am looking for it not only for the CreateFile). Anyone can point me to such documentation (books, web pages, etc) will be much appreciated. Life is a river with mist ahead...

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      I don't know if there is such a list but what you can do is use the Error Lookup tool. It is already in the tools in Visual C++ 6. You give the error code and it displays the corresponding error string.

      N 1 Reply Last reply
      0
      • C Cedric Moonen

        I don't know if there is such a list but what you can do is use the Error Lookup tool. It is already in the tools in Visual C++ 6. You give the error code and it displays the corresponding error string.

        N Offline
        N Offline
        Nilesh K
        wrote on last edited by
        #3

        Alternate to error lookup you can as well use FormatMessage API(Though output is same in either case ).

        - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

        D 1 Reply Last reply
        0
        • N Nilesh K

          Alternate to error lookup you can as well use FormatMessage API(Though output is same in either case ).

          - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

          D Offline
          D Offline
          Dimitris Vikeloudas
          wrote on last edited by
          #4

          Thanks for your help. I am aware of the FormatMessage API. The Error Lookup is also a good tool. However, all these come from the wrong direction; once you know the error. My problem is that I cannot find documentation about all possible errors. I would like to write a switch statement of the GetLastError numbers and direct my code to handle important errors in a more appropriate manner than reporting them to the user. And there is where my problem comes. I do not have a list of those errors; not only for CreateFile but for almost and window function. Look the UNIX manual for open() (E.g. in http://www.rt.com/man/open.2.html) They have a list of all possible errno values that open may return, not all possible errno values in the whole O.S. Why Microsoft never does that for Win32?? Or if it did where can I find it? Thanks for any help Life is river with mist ahead...

          G 1 Reply Last reply
          0
          • D Dimitris Vikeloudas

            Thanks for your help. I am aware of the FormatMessage API. The Error Lookup is also a good tool. However, all these come from the wrong direction; once you know the error. My problem is that I cannot find documentation about all possible errors. I would like to write a switch statement of the GetLastError numbers and direct my code to handle important errors in a more appropriate manner than reporting them to the user. And there is where my problem comes. I do not have a list of those errors; not only for CreateFile but for almost and window function. Look the UNIX manual for open() (E.g. in http://www.rt.com/man/open.2.html) They have a list of all possible errno values that open may return, not all possible errno values in the whole O.S. Why Microsoft never does that for Win32?? Or if it did where can I find it? Thanks for any help Life is river with mist ahead...

            G Offline
            G Offline
            geo_m
            wrote on last edited by
            #5

            Well, maybe because it's difficult to maintain such a documentation. If you're interested, you can look into the <winerror.h> header, where most of errors are described (found in any good Windows SDK) ;-) Don't know if it does any good to you, but at least tried ;-)

            1 Reply Last reply
            0
            • D Dimitris Vikeloudas

              I want to use CreateFile for creating of new files, overidding existing ones or just simply open them in various modes (depending on my applications' requirements). I know that when it fails it returns INVALID_HANDLE_VALUE and I have to use the GetLastError to find why. However, the GetLastError is a generic system function. Is anywhere any documentation about what errors can be the result of CreateFile. How do I know e.g. if I failed 'cause tried to create an existing file, tried to open an non-existing file, do not have enough disk space, do not have access to the parent directory, lost connection with a remote file store etc. A cross reference list function-possible failures would be usefull for any Win32 function (I am looking for it not only for the CreateFile). Anyone can point me to such documentation (books, web pages, etc) will be much appreciated. Life is a river with mist ahead...

              RaviBeeR Offline
              RaviBeeR Offline
              RaviBee
              wrote on last edited by
              #6

              Consider using CFile::Open() instead. That will allow you to switch on these[^] error codes contained within a thrown CFileException. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

              1 Reply Last reply
              0
              • D Dimitris Vikeloudas

                I want to use CreateFile for creating of new files, overidding existing ones or just simply open them in various modes (depending on my applications' requirements). I know that when it fails it returns INVALID_HANDLE_VALUE and I have to use the GetLastError to find why. However, the GetLastError is a generic system function. Is anywhere any documentation about what errors can be the result of CreateFile. How do I know e.g. if I failed 'cause tried to create an existing file, tried to open an non-existing file, do not have enough disk space, do not have access to the parent directory, lost connection with a remote file store etc. A cross reference list function-possible failures would be usefull for any Win32 function (I am looking for it not only for the CreateFile). Anyone can point me to such documentation (books, web pages, etc) will be much appreciated. Life is a river with mist ahead...

                RaviBeeR Offline
                RaviBeeR Offline
                RaviBee
                wrote on last edited by
                #7

                Consider using CFile::Open() instead. That will allow you to switch on these[^] error codes contained within a CFileException. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                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