Skip to content

Commit 41f28b6

Browse files
authored
fix: Fix Windows 32-bit build errors (#223)
1 parent ae4f023 commit 41f28b6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

platforms/windows/src/adapter.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl Adapter {
195195
// than the client area of the window. DefWindowProc can handle those.
196196
// First, cast the lparam to i32, to handle inconsistent conversion
197197
// behavior in senders.
198-
let objid: i32 = (lparam.0 & 0xFFFFFFFF) as _;
198+
let objid = normalize_objid(lparam);
199199
if objid < 0 && objid != UiaRootObjectId && objid != OBJID_CLIENT.0 {
200200
return None;
201201
}
@@ -210,6 +210,15 @@ impl Adapter {
210210
}
211211
}
212212

213+
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
214+
fn normalize_objid(lparam: LPARAM) -> i32 {
215+
(lparam.0 & 0xFFFFFFFF) as _
216+
}
217+
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
218+
fn normalize_objid(lparam: LPARAM) -> i32 {
219+
lparam.0 as _
220+
}
221+
213222
struct WmGetObjectResult {
214223
hwnd: HWND,
215224
wparam: WPARAM,

platforms/windows/src/subclass.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ use windows::{
1313

1414
use crate::{Adapter, QueuedEvents, UiaInitMarker};
1515

16+
// Work around a difference between the SetWindowLongPtrW API definition
17+
// in windows-rs on 32-bit and 64-bit Windows.
18+
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
19+
type LongPtr = isize;
20+
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
21+
type LongPtr = i32;
22+
1623
const PROP_NAME: PCWSTR = w!("AccessKitAdapter");
1724

1825
type LazyAdapter = Lazy<Adapter, Box<dyn FnOnce() -> Adapter>>;
@@ -70,7 +77,7 @@ impl SubclassImpl {
7077
let result: Result<()> = Err(Error::from_win32());
7178
result.unwrap();
7279
}
73-
self.prev_wnd_proc = unsafe { transmute::<isize, WNDPROC>(result) };
80+
self.prev_wnd_proc = unsafe { transmute::<LongPtr, WNDPROC>(result) };
7481
}
7582

7683
fn uninstall(&self) {
@@ -81,7 +88,7 @@ impl SubclassImpl {
8188
SetWindowLongPtrW(
8289
self.hwnd,
8390
GWLP_WNDPROC,
84-
transmute::<WNDPROC, isize>(self.prev_wnd_proc),
91+
transmute::<WNDPROC, LongPtr>(self.prev_wnd_proc),
8592
)
8693
};
8794
if result == 0 {

0 commit comments

Comments
 (0)