{"record":{"id":"0f97ed9e3af432f2","repo":"ramensoftware/windhawk","slug":"atl-exception-hresult-0x-08x","errorCode":null,"errorMessage":"ATL exception: HRESULT 0x{:08X}","messagePattern":"ATL exception: HRESULT 0x(.+?)","errorType":"exception","errorClass":"std::runtime_error","httpStatus":null,"severity":"error","filePath":"src/windhawk/app/stdafx.h","lineNumber":28,"sourceCode":"#define NOMINMAX\n\n//////////////////////////////////////////////////////////////////////////\n// WTL\n\n#define _WTL_NO_CSTRING\n#define _WTL_NO_WTYPES\n#define _WTL_NO_UNION_CLASSES\n#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS\n\n// Make ATL throws catchable via catch(const std::exception&).\n#define _ATL_CUSTOM_THROW\n\n#include <winerror.h>  // HRESULT\n#include <format>\n#include <stdexcept>\n\n[[noreturn]] inline void AtlThrow(HRESULT hr) {\n    throw std::runtime_error(std::format(\"ATL exception: HRESULT 0x{:08X}\",\n                                         static_cast<unsigned long>(hr)));\n}\n\n#include <atlbase.h>\n#include <atlfile.h>\n#include <atlstr.h>\n#include <atltypes.h>\n#include <atlutil.h>\n\n#include <atlapp.h>\nextern CAppModule _Module;\n\n#include <atlwin.h>\n\n#include <atlcrack.h>\n#include <atlctrls.h>\n#include <atlctrlx.h>\n// #include <atldlgs.h>","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/ramensoftware/windhawk/blob/61d99ed8e182e1af1b60109612b6763ad1b4b74e/src/windhawk/app/stdafx.h#L10-L46","documentation":"This repository replaces ATL's AtlThrow with a custom inline function that throws std::runtime_error carrying the failing HRESULT formatted as 0x{:08X}. Any ATL/COM helper (CAtlFile, CString allocation, etc.) that detects failure calls it, so ATL-originated failures surface as this message with the specific HRESULT embedded.","triggerScenarios":"Any ATL API returning a failed HRESULT — file operations via CAtlFile/CAtlFileMapping, string allocation failures, COM calls wrapped in ATL helpers that call AtlThrow on error.","commonSituations":"File not found or access denied during ATL file I/O (0x80070002, 0x80070005); out-of-memory on string allocation (0x8007000E); COM interface failures in storage/registry helpers.","solutions":["Decode the HRESULT in the message to identify the underlying Win32/COM failure","For 0x80070005, fix file/registry permissions for the involved path","For 0x80070002, verify the file path passed to the ATL helper exists","Wrap ATL-heavy sections in try/catch (std::runtime_error) and inspect e.what()","Check available memory if the HRESULT indicates E_OUTOFMEMORY"],"exampleFix":"// before: unhandled ATL failure crashes the app\nCAtlFile file; file.Create(path, ...);\n// after\ntry {\n    CAtlFile file;\n    file.Create(path, ...);\n} catch (const std::exception& e) {\n    Log(L\"ATL failure: %hs\", e.what());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    // ATL file / COM operations\n} catch (const std::runtime_error& e) {\n    HRESULT hr = ParseHresultFromAtlMessage(e.what());\n    HandleHresult(hr);\n}","preventionTips":["Check file existence and permissions before ATL file calls","Decode logged HRESULTs (0x80070002/05/0E) to target the root cause","Wrap all ATL-heavy code paths in try/catch"],"tags":["atl","com","hresult","cpp","windows"],"backgroundTag":"api-error-response","analyzedSha":"61d99ed8e182e1af1b60109612b6763ad1b4b74e","analyzedAt":"2026-09-12T14:02:41.115Z","contentChangedAt":"2026-09-12T14:02:41.115Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}