Skip to content

Commit 8492dd9

Browse files
committed
refactor(win32): make class conflict ignorance as a feature
1 parent a0114ab commit 8492dd9

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

winio-ui-win32/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ sync-unsafe-cell = { version = "0.1", optional = true }
6565
embed-resource = "3"
6666

6767
[features]
68+
ignore-class-conflict = []
6869
dark-mode = ["dep:slim-detours-sys", "dep:sync-unsafe-cell"]

winio-ui-win32/src/ui/window.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ use std::{
77
use compio::driver::syscall;
88
use inherit_methods_macro::inherit_methods;
99
use widestring::{U16CStr, U16CString, u16cstr};
10+
#[cfg(feature = "ignore-class-conflict")]
11+
use windows_sys::Win32::Foundation::ERROR_CLASS_ALREADY_EXISTS;
1012
use windows_sys::Win32::{
11-
Foundation::{
12-
ERROR_CLASS_ALREADY_EXISTS, ERROR_INVALID_HANDLE, HWND, LPARAM, LRESULT, POINT,
13-
SetLastError, WPARAM,
14-
},
13+
Foundation::{ERROR_INVALID_HANDLE, HWND, LPARAM, LRESULT, POINT, SetLastError, WPARAM},
1514
Graphics::Gdi::{GetStockObject, MapWindowPoints, WHITE_BRUSH},
1615
System::LibraryLoader::GetModuleHandleW,
1716
UI::{
@@ -343,6 +342,7 @@ fn register() {
343342
};
344343
match syscall!(BOOL, unsafe { RegisterClassExW(&cls) }) {
345344
Ok(_) => {}
345+
#[cfg(feature = "ignore-class-conflict")]
346346
Err(e) if e.raw_os_error() == Some(ERROR_CLASS_ALREADY_EXISTS as _) => {
347347
// The class is already registered. We choose to ignore this error,
348348
// and hope that the class is still valid.

winio/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ enable_log = ["compio/enable_log", "compio-log/enable_log"]
5858

5959
nightly = ["compio/nightly", "cyper/nightly"]
6060
win32-dark-mode = ["winio-ui-win32/dark-mode"]
61+
win32-ignore-class-conflict = ["winio-ui-win32/ignore-class-conflict"]
6162
objc-static = ["winio-ui-app-kit/objc-static"]

0 commit comments

Comments
 (0)