cwinapigetlasterror

List of GetLastError() error codes for every winapi function


Is there a list that provides error codes that are returned by given winapi function through GetLastError() ? is there any official or unofficial resource that provides such documentation ?

for example winsock function documentation pages on MSDN provide table of possible WSAGetLastError() codes, while other winapi functions do not have such list for every possible error of given function and this is the exact problem addressed in this question, I am asking for similar documentation for every winapi function.

What I am not asking for:

EDIT: I am aware of this question, it deals with one particular function (CreateFile) which seems to be exception because third party file systems can provide their own error codes, even if most functions fall under this case, there still should be most common/standard error codes

thanks in advance


Solution

  • There is no such list. In fact, there cannot be one, because there are API calls, that aren't even in control of the entire set of error codes they can return (consider, for example, EnumWindows, where user-provided code sets the error code).

    Some API calls provide a partial list of error codes they can return. On those cases it is part of the documented contract, and your code can be written to account for those error codes. Keep in mind, that those lists are usually never complete, so your code needs to be prepared to deal with other error codes as well.

    In short, error handling needs to be implemented on a case-by-case basis. There are common patterns, but there is no single catch-all implementation.