{"record":{"id":"73c75e8e700c963f","repo":"BigPizzaV3/CodexPlusPlus","slug":"setthreaddpiawarenesscontext-failed","errorCode":null,"errorMessage":"SetThreadDpiAwarenessContext failed","messagePattern":"SetThreadDpiAwarenessContext failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/launcher.rs","lineNumber":1542,"sourceCode":"            bytes,\n            content_type.to_string(),\n            \"helper.dream_skin_image_ok\",\n        ),\n        Err(_) => not_found(),\n    }\n}\n\n#[cfg(windows)]\nfn windows_logical_cursor_position() -> anyhow::Result<(i32, i32)> {\n    use windows::Win32::Foundation::POINT;\n    use windows::Win32::UI::HiDpi::{\n        DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED, SetThreadDpiAwarenessContext,\n    };\n    use windows::Win32::UI::WindowsAndMessaging::GetCursorPos;\n\n    let previous = unsafe { SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) };\n    if previous.0.is_null() {\n        anyhow::bail!(\"SetThreadDpiAwarenessContext failed\");\n    }\n    let mut point = POINT::default();\n    let result = unsafe { GetCursorPos(&mut point) };\n    unsafe {\n        SetThreadDpiAwarenessContext(previous);\n    }\n    result.ok().context(\"GetCursorPos failed\")?;\n    Ok((point.x, point.y))\n}\n\nfn overlay_image_content_type(path: &Path) -> Option<&'static str> {\n    match path\n        .extension()\n        .and_then(|extension| extension.to_str())\n        .map(str::to_ascii_lowercase)\n        .as_deref()\n    {\n        Some(\"png\") => Some(\"image/png\"),","sourceCodeStart":1524,"sourceCodeEnd":1560,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/launcher.rs#L1524-L1560","documentation":"On Windows, before calling GetCursorPos the code switches the thread DPI awareness to DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED so coordinates match GDI-scaled expectations. SetThreadDpiAwarenessContext returns NULL on failure (invalid context value or pre-Windows-10-1607 OS), and the code bails instead of reading potentially wrong coordinates.","triggerScenarios":"Calling the cursor-position helper on a Windows version older than 1607 (Anniversary Update) where SetThreadDpiAwarenessContext does not exist, or with an invalid DPI awareness context constant.","commonSituations":"Running the manager app on legacy Windows 7/8 or early Windows 10 builds; DPI-related API surface unavailable in the linked SDK target.","solutions":["Run on Windows 10 version 1607+ where SetThreadDpiAwarenessContext is available","Wrap the call with GetProcAddress/LoadLibrary on user32.dll and skip the DPI switch if the function is unavailable (treat as non-fatal)","Keep the current thread DPI context if switching fails and document coordinate-space assumptions"],"exampleFix":"// before\nlet previous = unsafe { SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) };\nif previous.0.is_null() { anyhow::bail!(\"SetThreadDpiAwarenessContext failed\"); }\n// after\nlet previous = unsafe { SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) };\nlet switched = !previous.0.is_null();\n// ... GetCursorPos ...\nif switched { unsafe { SetThreadDpiAwarenessContext(previous); } }","handlingStrategy":"try-catch","validationCode":"// runtime check: is the API available?\nlet ok = version >= windows_version(10, 0, 14393); // 1607 Anniversary Update\nif !ok { skip_dpi_switch = true; }","typeGuard":"fn supports_set_thread_dpi_awareness_context() -> bool {\n    // true only on Win10 1607+\n    is_windows_at_least(10, 0, 14393)\n}","tryCatchPattern":"match get_cursor_pos_gdiscaled() {\n    Ok(p) => use_point(p),\n    Err(e) if e.to_string().contains(\"SetThreadDpiAwarenessContext\") => {\n        let p = get_cursor_pos_unswitched()?; // fallback without DPI switch\n        use_point(p);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Verify minimum supported Windows version for the app","Null-check DPI API return values and degrade gracefully","Use GetProcAddress to detect optional DPI APIs at runtime","Test cursor/coordinate features on legacy Windows builds"],"tags":["rust","windows","win32","dpi","os-compatibility"],"backgroundTag":"unsupported-platform","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}