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