Are the error codes defined in WinError.h
free to be hijacked and returned my by own code?
There are some generic Win32 error codes defined:
ERROR_FILE_NOT_FOUND
: "The system cannot find the file specified."
that of course i could use for my own purpose when a file is not found.
Then there are still some generic errors:
ERROR_ACCESS_DENIED
: "Access is denied."
but it's generally understood that this error comes when trying to access a file. i might have an HttpGet()
function that returns ERROR_ACCESS_DENIED
if the server returns a 401
.
But then there are codes that are defined as being for a particular purpose. Imagine my HttpGet()
function throws an error if the https
certificate is not a type we support:
ERROR_IPSEC_IKE_INVALID_CERT_TYPE
: "Invalid certificate type"
except that code is defined quite clearly in WinError.h
as belonging to IPSec:
///////////////////////////////////////////////////
// //
// Start of IPSec Error codes //
// //
// 13000 to 13999 //
///////////////////////////////////////////////////
...
//
// MessageId: ERROR_IPSEC_IKE_INVALID_CERT_TYPE
//
// MessageText:
//
// Invalid certificate type
//
#define ERROR_IPSEC_IKE_INVALID_CERT_TYPE 13819L
But the error text is exactly what i want!
We have a financial system that requires a 2nd user to approve a transaction; this means that the entered credentials must be a different user than the first person:
MK_E_MUSTBOTHERUSER
: "User input required for operation to succeed"
or perhaps:
ERROR_LOGON_TYPE_NOT_GRANTED
: "Logon failure: the user has not been granted the requested logon type at this computer."
i get the sense that spelunking through WinError, cherry-picking error codes by the string they show and re-purposing them to indicate errors they were not designed for, is something Raymond would give me a slap for.
Are Windows error codes a freely available "pool" of error codes? Or are all Windows error codes only to be returned from Microsoft's code?
If i'm creating HRESULTS
, i need to use some code. And it would be great if the user could call FormatMessage
to turn my HRESULT
into a string. (Especially since my return HRESULT could either me either my own code, or an HRESULT that was returned to me from Microsoft code).