Title: SetLastError function (errhandlingapi.h) - Win32 apps | Microsoft Learn
Open Graph Title: SetLastError function (errhandlingapi.h) - Win32 apps
Description: Sets the last-error code for the calling thread.
Open Graph Description: Sets the last-error code for the calling thread.
Opengraph URL: https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-setlasterror
Domain: learn.microsoft.com
| color-scheme | light dark |
| twitter:card | summary_large_image |
| og:type | website |
| og:image:alt | Microsoft Learn |
| og:image | https://learn.microsoft.com/en-us/media/open-graph-image.png |
| platform_id | 00222883-5f60-11ec-4ded-a18ed6242384 |
| scope | Windows,Desktop |
| locale | en-us |
| uhfHeaderId | MSDocsHeader-WinDevCenter |
| page_type | conceptual |
| adobe-target | true |
| breadcrumb_path | /windows/desktop/api/breadcrumb/toc.json |
| ms.service | windows-api-desktop-tech |
| ms.subservice | sdk-api-reference |
| ms.topic | reference |
| ms.author | kbridge |
| author | karl-bridge-microsoft |
| feedback_system | Standard |
| feedback_product_url | https://www.microsoft.com/en-us/windowsinsider/feedbackhub/fb |
| feedback_help_link_url | https://learn.microsoft.com/answers/tags/224/windows-api-win32/ |
| feedback_help_link_type | get-help-at-qna |
| UID | NF:errhandlingapi.SetLastError |
| old-location | base\setlasterror.htm |
| tech.root | Debug |
| ms.assetid | d9da833f-36ca-4046-8d2f-cd4449dd3c63 |
| ms.date | 2024-02-02T00:00:00Z |
| ms.keywords | SetLastError, SetLastError function, _win32_setlasterror, base.setlasterror, errhandlingapi/SetLastError |
| req.header | errhandlingapi.h |
| req.include-header | Windows.h |
| req.target-type | Windows |
| req.target-min-winverclnt | Windows XP [desktop apps \| UWP apps] |
| req.target-min-winversvr | Windows Server 2003 [desktop apps \| UWP apps] |
| req.lib | Kernel32.lib |
| req.dll | Kernel32.dll |
| targetos | Windows |
| ms.custom | 19H1 |
| TopicType | kbSyntax |
| APIType | DllExport |
| APILocation | vertdll.dll |
| APIName | SetLastError |
| document_id | fc45bc4c-8278-02ba-0f4c-1285eab5ac4b |
| document_version_independent_id | f7164bb0-c7fe-23ee-1386-39870d5b207d |
| updated_at | 2025-08-27T22:00:00Z |
| original_content_git_url | https://cpubwin.visualstudio.com/DefaultCollection/win32/_git/sdk-api-build?path=/sdk-api-src/content/errhandlingapi/nf-errhandlingapi-setlasterror.md&version=GBlive&_a=contents |
| gitcommit | https://cpubwin.visualstudio.com/DefaultCollection/win32/_git/sdk-api-build/commit/0bbc807636f66bcedbaa95e8d0b17a0152e6ef70?path=/sdk-api-src/content/errhandlingapi/nf-errhandlingapi-setlasterror.md&_a=contents |
| git_commit_id | 0bbc807636f66bcedbaa95e8d0b17a0152e6ef70 |
| site_name | Docs |
| depot_name | MSDN.sdk-api-build |
| schema | Conceptual |
| toc_rel | toc.json |
| pdf_url_template | https://learn.microsoft.com/pdfstore/en-us/MSDN.sdk-api-build/{branchName}{pdfName} |
| search.mshattr.devlang | c++ |
| word_count | 212 |
| asset_id | errhandlingapi/nf-errhandlingapi-setlasterror |
| item_type | Content |
| source_path | sdk-api-src/content/errhandlingapi/nf-errhandlingapi-setlasterror.md |
| previous_tlsh_hash | 6B646021E00E5F11CEC3D90919D1F29EB6E5C4D07954ABF431299A92D3922DB32F585EF6914BAB42139321232165984FA4C4D76A803B423770542D8C5ABE3CB6A0DDA2796C |
| github_feedback_content_git_url | https://github.com/MicrosoftDocs/sdk-api/blob/docs/sdk-api-src/content/errhandlingapi/nf-errhandlingapi-setlasterror.md |
| markdown_url | https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-setlasterror?accept=text/markdown |
| cmProducts | https://authoring-docs-microsoft.poolparty.biz/devrel/bcbcbad5-4208-4783-8035-8481272c98b8 |
| spProducts | https://authoring-docs-microsoft.poolparty.biz/devrel/43b2e5aa-8a6d-4de2-a252-692232e5edc8 |
Links:
Viewport: width=device-width, initial-scale=1.0