SetLastError function

Namespace: Win32

Sets the last-error code for the calling thread.

Syntax

VOID SetLastError(
    DWORD dwErrCode
);

Parameters

dwErrCode
The error code to be set for the calling thread. Use the GetLastError function to retrieve the error code later.

Return value

This function does not return a value.

Remarks

Example

#include <windows.h>
#include <stdio.h>

int main(void)
{
    // Force an error
    SetLastError(ERROR_FILE_NOT_FOUND);
    DWORD err = GetLastError();
    printf("Last error: %lu\\n", err);
    return 0;
}

See also