{"record":{"id":"c80d541e78dc0f7f","repo":"rustdesk/rustdesk","slug":"failed-to-registerclassexa-error","errorCode":null,"errorMessage":"Failed to RegisterClassExA, error {}","messagePattern":"Failed to RegisterClassExA, error (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"libs/scrap/src/dxgi/mag.rs","lineNumber":383,"sourceCode":"                cbSize: size_of::<WNDCLASSEXA>() as _,\n                style: 0,\n                lpfnWndProc: Some(DefWindowProcA),\n                cbClsExtra: 0,\n                cbWndExtra: 0,\n                hInstance: instance,\n                hIcon: 0 as _,\n                hCursor: LoadCursorA(NULL as _, IDC_ARROW as _),\n                hbrBackground: 0 as _,\n                lpszClassName: s.magnifier_host_class.as_ptr() as _,\n                lpszMenuName: 0 as _,\n                hIconSm: 0 as _,\n            };\n\n            // Ignore the error which may happen when the class is already registered.\n            if 0 == RegisterClassExA(&wcex) {\n                let code = GetLastError();\n                if code != ERROR_CLASS_ALREADY_EXISTS {\n                    return Err(Error::new(\n                        ErrorKind::Other,\n                        format!(\n                            \"Failed to RegisterClassExA, error {}\",\n                            Error::from_raw_os_error(code as _)\n                        ),\n                    ));\n                }\n            }\n\n            // Create the host window.\n            s.host_window = CreateWindowExA(\n                WS_EX_LAYERED,\n                s.magnifier_host_class.as_ptr(),\n                s.host_window_name.as_ptr(),\n                WS_POPUP,\n                0,\n                0,\n                0,","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/7aa98d43cf1962a7a29ec16ffef42974377ef11e/libs/scrap/src/dxgi/mag.rs#L365-L401","documentation":"RegisterClassExA failed with an error other than ERROR_CLASS_ALREADY_EXISTS (which is deliberately ignored so a class registered earlier in the process is reused). The host window class is required before creating the magnifier host window; other failures typically mean desktop heap exhaustion or a class-name collision with different attributes in the same process/session.","triggerScenarios":"Creating many Magnifier instances (or leaking host classes) until the session desktop heap is exhausted; another component registering the same class name with different parameters; running in a restricted desktop/window station.","commonSituations":"Long-running capture processes repeatedly constructing and tearing down capturers; services or scheduled tasks running on a non-interactive desktop with a tiny desktop heap; co-existing software that uses the same window class name string.","solutions":["Reuse a single Magnifier capturer per process instead of constructing one per session/stream.","Check the error code in the message: ERROR_NOT_ENOUGH_MEMORY points at desktop heap — raise the desktop heap size or move to the interactive session.","Rename the host/magnifier class names to something unique to your application.","Fall back to the DXGI capturer when class registration fails."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_register_class_error(e: &std::io::Error) -> bool {\n    e.to_string().contains(\"RegisterClassExA\")\n}","tryCatchPattern":"let mag = match magnifier::Magnifier::new(origin, w, h) {\n    Ok(m) => m,\n    Err(e) if is_register_class_error(&e) => {\n        log::error!(\"host class registration failed: {e}\");\n        return fallback_to_dxgi();\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Create the magnifier capturer once per process and reuse it (ERROR_CLASS_ALREADY_EXISTS is already tolerated).","Check the error code: ERROR_NOT_ENOUGH_MEMORY points at desktop-heap exhaustion — reduce window churn or raise SharedSection's third value.","Use unique window-class names to avoid collisions with other software."],"tags":["windows","win32","window-class","desktop-heap","rust","magnification-api"],"backgroundTag":null,"analyzedSha":"7aa98d43cf1962a7a29ec16ffef42974377ef11e","analyzedAt":"2026-08-16T06:17:34.842Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}