What is the CsWin32 way to handle API failures and access error information? #1092
-
The title says it all.
The above is not reliable and sometime returns |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
CsWin32 generates APIs that follow the same Win32 error reporting standard that you might have in manually written P/Invokes. You should refer to the documentation of the individual win32 API to learn how to get error information. Some APIs call SetLastError while others do not. You should only call |
Beta Was this translation helpful? Give feedback.
-
Is there enum for Win32 erro like Win32Error.ERROR_ACCESS_DENIED? |
Beta Was this translation helpful? Give feedback.
CsWin32 generates APIs that follow the same Win32 error reporting standard that you might have in manually written P/Invokes. You should refer to the documentation of the individual win32 API to learn how to get error information. Some APIs call SetLastError while others do not. You should only call
GetLastWin32Error
directly after a call to a win32 API that is documented as callingSetLastError
and should only do so when it says you should (e.g. when you get a null result).The reason for this is if you call an API that does not call SetLastError (either because it never does, or only does in error cases), then by calling
GetLastWin32Error
you'll be getting the code from some prior call …