BigPizzaV3/CodexPlusPlus · error · anyhow::Error
SetThreadDpiAwarenessContext failed
Error message
SetThreadDpiAwarenessContext failed
What it means
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.
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
Example fix
// before
let previous = unsafe { SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) };
if previous.0.is_null() { anyhow::bail!("SetThreadDpiAwarenessContext failed"); }
// after
let previous = unsafe { SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) };
let switched = !previous.0.is_null();
// ... GetCursorPos ...
if switched { unsafe { SetThreadDpiAwarenessContext(previous); } } Defensive patterns
Strategy: try-catch
Validate before calling
// runtime check: is the API available?
let ok = version >= windows_version(10, 0, 14393); // 1607 Anniversary Update
if !ok { skip_dpi_switch = true; } Type guard
fn supports_set_thread_dpi_awareness_context() -> bool {
// true only on Win10 1607+
is_windows_at_least(10, 0, 14393)
} Try / catch
match get_cursor_pos_gdiscaled() {
Ok(p) => use_point(p),
Err(e) if e.to_string().contains("SetThreadDpiAwarenessContext") => {
let p = get_cursor_pos_unswitched()?; // fallback without DPI switch
use_point(p);
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Running the manager app on legacy Windows 7/8 or early Windows 10 builds; DPI-related API surface unavailable in the linked SDK target.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- failed to wait for Windows process id
- cannot terminate Windows process id
- cannot wait for Windows process id
- failed to open DevTools URL
- Native browser compatibility is Windows-only
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/73c75e8e700c963f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/launcher.rs:1542
bytes,
content_type.to_string(),
"helper.dream_skin_image_ok",
),
Err(_) => not_found(),
}
}
#[cfg(windows)]
fn windows_logical_cursor_position() -> anyhow::Result<(i32, i32)> {
use windows::Win32::Foundation::POINT;
use windows::Win32::UI::HiDpi::{
DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED, SetThreadDpiAwarenessContext,
};
use windows::Win32::UI::WindowsAndMessaging::GetCursorPos;
let previous = unsafe { SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED) };
if previous.0.is_null() {
anyhow::bail!("SetThreadDpiAwarenessContext failed");
}
let mut point = POINT::default();
let result = unsafe { GetCursorPos(&mut point) };
unsafe {
SetThreadDpiAwarenessContext(previous);
}
result.ok().context("GetCursorPos failed")?;
Ok((point.x, point.y))
}
fn overlay_image_content_type(path: &Path) -> Option<&'static str> {
match path
.extension()
.and_then(|extension| extension.to_str())
.map(str::to_ascii_lowercase)
.as_deref()
{
Some("png") => Some("image/png"),View on GitHub (pinned to b1ed92e5e4)