This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. Multiple threads do not overwrite each other's last-error code.
Visual Basic: Applications should callerr.LastDllError instead ofGetLastError.
_Post_equals_last_error_ DWORD GetLastError();
The return value is the calling thread's last-error code.
The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread's last-error code set it when they fail. However, some functions also set the last-error code when they succeed. If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not.
Functions executed by the calling thread set this value by calling theSetLastError function. You should call theGetLastError function immediately when a function's return value indicates that such a call will return useful data. That is because some functions callSetLastError with a zero when they succeed, wiping out the error code set by the most recently failed function.
To obtain an error string for system error codes, use theFormatMessage function. For a complete list of error codes provided by the operating system, seeSystem Error Codes.
The error codes returned by a function are not part of the Windows API specification and can vary by operating system or device driver. For this reason, we cannot provide the complete list of error codes that can be returned by each function. There are also many functions whose documentation does not include even a partial list of error codes that can be returned.
Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is reserved for application-defined error codes; no system error code has this bit set. If you are defining an error code for your application, set this bit to one. That indicates that the error code has been defined by an application, and ensures that your error code does not conflict with any error codes defined by the system.
To convert a system error into anHRESULT value, use theHRESULT_FROM_WIN32 macro.
For an example, seeRetrieving the Last-Error Code.
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2003 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | errhandlingapi.h (include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
Was this page helpful?
Was this page helpful?