Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

GetLastError function (errhandlingapi.h)

  • 2024-02-06
Feedback

In this article

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.

Syntax

_Post_equals_last_error_ DWORD GetLastError();

Return value

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.

Remarks

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.

Examples

For an example, seeRetrieving the Last-Error Code.

Requirements

RequirementValue
Minimum supported clientWindows XP [desktop apps | UWP apps]
Minimum supported serverWindows Server 2003 [desktop apps | UWP apps]
Target PlatformWindows
Headererrhandlingapi.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See also

Error Handling Functions

FormatMessage

HRESULT_FROM_WIN32

Last-Error Code

SetLastError

SetLastErrorEx

Vertdll APIs available in VBS enclaves


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo