ramensoftware/windhawk · error · std::runtime_error
ATL exception: HRESULT 0x
Error message
ATL exception: HRESULT 0x{:08X} What it means
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.
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
Example fix
// before: unhandled ATL failure crashes the app
CAtlFile file; file.Create(path, ...);
// after
try {
CAtlFile file;
file.Create(path, ...);
} catch (const std::exception& e) {
Log(L"ATL failure: %hs", e.what());
} Defensive patterns
Strategy: try-catch
Try / catch
try {
// ATL file / COM operations
} catch (const std::runtime_error& e) {
HRESULT hr = ParseHresultFromAtlMessage(e.what());
HandleHresult(hr);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- throw ResultException(failure)
- throw PortableSettingsException(error)
- Failed to start the global hooking session
- Missing path value
- Missing RegistryKey value
AI-assisted analysis of ramensoftware/windhawk@61d99ed8e1 (2026-09-12).
Data as JSON: /api/errors/0f97ed9e3af432f2.
Report an issue: GitHub.
Appendix: source
Thrown at src/windhawk/app/stdafx.h:28
#define NOMINMAX
//////////////////////////////////////////////////////////////////////////
// WTL
#define _WTL_NO_CSTRING
#define _WTL_NO_WTYPES
#define _WTL_NO_UNION_CLASSES
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
// Make ATL throws catchable via catch(const std::exception&).
#define _ATL_CUSTOM_THROW
#include <winerror.h> // HRESULT
#include <format>
#include <stdexcept>
[[noreturn]] inline void AtlThrow(HRESULT hr) {
throw std::runtime_error(std::format("ATL exception: HRESULT 0x{:08X}",
static_cast<unsigned long>(hr)));
}
#include <atlbase.h>
#include <atlfile.h>
#include <atlstr.h>
#include <atltypes.h>
#include <atlutil.h>
#include <atlapp.h>
extern CAppModule _Module;
#include <atlwin.h>
#include <atlcrack.h>
#include <atlctrls.h>
#include <atlctrlx.h>
// #include <atldlgs.h>View on GitHub (pinned to 61d99ed8e1)