Click to Rate and Give Feedback
MSDN
MSDN Library
Diagnostics
Error Handling
 SetLastError Function

  Switch on low bandwidth view
SetLastError Function

Sets the last-error code for the calling thread.

Syntax

C++
void WINAPI SetLastError(
  __in  DWORD dwErrCode
);

Parameters

dwErrCode [in]

The last-error code for the thread.

Return Value

This function does not return a value.

Remarks

The last-error code is kept in thread local storage so that multiple threads do not overwrite each other's values.

Most functions call SetLastError or SetLastErrorEx only when they fail. However, some system functions call SetLastError or SetLastErrorEx under conditions of success; those cases are noted in each function's documentation.

Applications can optionally retrieve the value set by this function by using the GetLastError function immediately after a function fails.

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 indicate that the error code has been defined by your application and to ensure that your error code does not conflict with any system-defined error codes.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See Also

Error Handling Functions
GetLastError
Last-Error Code
SetLastErrorEx

Send comments about this topic to Microsoft

Build date: 7/2/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Sub SetLastError(ByVal errorCode As Integer)
End Sub
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern void SetLastError(int errorCode);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker