Each thread will have its own last error code. The Windows API will set the last error code on the calling thread.
You should always call the GetLastError
function immediately after checking a Windows API function's return value.
The majority of Windows API functions set the last error code when they fail. Some will also set the last error code when they succeed. There are a number of functions that do not set the last error code. Always refer to the Windows API function's documentation.
It is unsafe to use FORMAT_MESSAGE_FROM_SYSTEM
without FORMAT_MESSAGE_IGNORE_INSERTS
when using the FormatMessage
function to get a description of an error code.