SetLastError
SetLastError is a Windows API function that sets the calling thread's last-error code, a thread-local DWORD. The last-error code is used in conjunction with GetLastError to convey detailed error information from Windows API calls to the caller. Applications typically rely on the return value of a function to determine success or failure and then query the last error only when a failure is indicated.
The function signature is VOID SetLastError(DWORD dwErrCode). The value is stored in thread-local storage and is
Usage guidelines emphasize that when a Windows API fails, it usually returns a failure indicator (such as
Scope and caveats include that the last-error value is per-thread and is not preserved across process boundaries