ramensoftware/windhawk · error · SettingsError

RegQueryValueEx (size)

Error message

RegQueryValueEx (size)

What it means

The first (size-query) call to RegQueryValueExW inside query_raw failed with an OS error code other than ERROR_SUCCESS, ERROR_MORE_DATA, or ERROR_FILE_NOT_FOUND. This is the length-probing half of a registry read; the wrapped message carries the Win32 function name and error code.

Solutions

  1. Check the wrapped OS code (likely ERROR_ACCESS_DENIED or ERROR_INVALID_HANDLE) and address that cause.
  2. Re-open the key before reading; ensure the handle is valid and not closed early.
  3. Request the needed access rights (KEY_READ / KEY_QUERY_VALUE) when opening the key.
  4. Verify the registry path and whether redirection/virtualization affects the key location.

Example fix

// before
let val = settings.get_string("x").ok(); // error swallowed
// after
let val = settings.get_string("x").map_err(|e| {
    eprintln!("registry read failed: {e}");
    e
})?;
Defensive patterns

Strategy: try-catch

Validate before calling

// verify key is readable before reads: ensure the settings object opened successfully and the key exists

Try / catch

match settings.get_string("x") {
    Ok(v) => v,
    Err(e) if e.message().starts_with("RegQueryValueEx") => {
        eprintln!("registry read failed ({e}); check key handle and ACLs");
        None
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Reading any value (get_string/get_int/get_binary/enum_values) when the parent key handle is bad or closed, access is denied for the value, or the registry call fails with e.g. ERROR_ACCESS_DENIED or ERROR_INVALID_HANDLE. A simply missing value returns Ok(None) instead.

Common situations: Opening the key read-only with insufficient ACLs; key closed between open and read; registry virtualization issues; corrupted key state after an aborted operation.

Related errors


AI-assisted analysis of ramensoftware/windhawk@61d99ed8e1 (2026-09-12). Data as JSON: /api/errors/b860540ff6e84476. Report an issue: GitHub.

Appendix: source

Thrown at src/windhawk-core/windows/src/registry.rs:425

        let mut value_type: u32 = 0;
        // First call: type + size only.
        // SAFETY: name_w is NUL-terminated; out params are valid; lpData null
        // with *lpcbData = 0 just queries the size.
        let rc = unsafe {
            RegQueryValueExW(
                hkey,
                name_w.as_ptr(),
                std::ptr::null(),
                &mut value_type,
                std::ptr::null_mut(),
                &mut size,
            )
        };
        if rc == ERROR_FILE_NOT_FOUND {
            return Ok(None);
        }
        if rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA {
            return Err(self.err("get", rc, "RegQueryValueEx (size)"));
        }
        let mut buf = vec![0u8; size as usize];
        let mut data_size = size;
        // SAFETY: buf has data_size bytes; out params valid.
        let rc = unsafe {
            RegQueryValueExW(
                hkey,
                name_w.as_ptr(),
                std::ptr::null(),
                &mut value_type,
                buf.as_mut_ptr(),
                &mut data_size,
            )
        };
        if rc == ERROR_FILE_NOT_FOUND {
            return Ok(None);
        }
        if rc != ERROR_SUCCESS {

View on GitHub (pinned to 61d99ed8e1)