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
- Check the wrapped OS code (likely ERROR_ACCESS_DENIED or ERROR_INVALID_HANDLE) and address that cause.
- Re-open the key before reading; ensure the handle is valid and not closed early.
- Request the needed access rights (KEY_READ / KEY_QUERY_VALUE) when opening the key.
- 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
- Open keys with minimal-but-sufficient access rights (KEY_QUERY_VALUE for reads).
- Keep the settings object alive while reading; do not close handles early.
- Distinguish missing values (Ok(None)) from real IO errors in your code.
- Log OS error codes wrapped in the message for support diagnostics.
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
- RegQueryValueEx (data)
- value name contains a NUL
- value is too large for the registry
- RegSetValueEx
- RegDeleteValue
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)