Skip to content

Commit 2f86c45

Browse files
authored
fix: Update windows-rs to 0.61 (#541)
1 parent f8c0d0a commit 2f86c45

File tree

8 files changed

+92
-49
lines changed

8 files changed

+92
-49
lines changed

Cargo.lock

Lines changed: 54 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

platforms/windows/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ accesskit = { version = "0.18.0", path = "../../common" }
2020
accesskit_consumer = { version = "0.27.0", path = "../../consumer" }
2121
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher"] }
2222
static_assertions = "1.1.0"
23-
windows-core = "0.58.0"
23+
windows-core = "0.61.0"
2424

2525
[dependencies.windows]
26-
version = "0.58.0"
26+
version = "0.61.1"
2727
features = [
28-
"implement",
2928
"Win32_Foundation",
3029
"Win32_Graphics_Gdi",
3130
"Win32_System_Com",

platforms/windows/examples/hello_world.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl ActionHandler for SimpleActionHandler {
197197
Action::Focus => {
198198
unsafe {
199199
PostMessageW(
200-
self.window,
200+
Some(self.window),
201201
SET_FOCUS_MSG,
202202
WPARAM(0),
203203
LPARAM(request.target.0 as _),
@@ -208,7 +208,7 @@ impl ActionHandler for SimpleActionHandler {
208208
Action::Click => {
209209
unsafe {
210210
PostMessageW(
211-
self.window,
211+
Some(self.window),
212212
CLICK_MSG,
213213
WPARAM(0),
214214
LPARAM(request.target.0 as _),
@@ -241,7 +241,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
241241
unsafe { DefWindowProcW(window, message, wparam, lparam) }
242242
}
243243
WM_PAINT => {
244-
unsafe { ValidateRect(window, None) }.unwrap();
244+
unsafe { ValidateRect(Some(window), None) }.unwrap();
245245
LRESULT(0)
246246
}
247247
WM_DESTROY => {
@@ -321,6 +321,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
321321

322322
fn create_window(title: &str, initial_focus: NodeId) -> Result<HWND> {
323323
let create_params = Box::new(WindowCreateParams(initial_focus));
324+
let module = HINSTANCE::from(unsafe { GetModuleHandleW(None)? });
324325

325326
let window = unsafe {
326327
CreateWindowExW(
@@ -334,7 +335,7 @@ fn create_window(title: &str, initial_focus: NodeId) -> Result<HWND> {
334335
CW_USEDEFAULT,
335336
None,
336337
None,
337-
GetModuleHandleW(None).unwrap(),
338+
Some(module),
338339
Some(Box::into_raw(create_params) as _),
339340
)?
340341
};
@@ -355,7 +356,7 @@ fn main() -> Result<()> {
355356
let _ = unsafe { ShowWindow(window, SW_SHOW) };
356357

357358
let mut message = MSG::default();
358-
while unsafe { GetMessageW(&mut message, HWND::default(), 0, 0) }.into() {
359+
while unsafe { GetMessageW(&mut message, None, 0, 0) }.into() {
359360
let _ = unsafe { TranslateMessage(&message) };
360361
unsafe { DispatchMessageW(&message) };
361362
}

platforms/windows/src/node.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ use accesskit_consumer::{FilterResult, Node, TreeState};
1818
use std::sync::{atomic::Ordering, Arc, Weak};
1919
use windows::{
2020
core::*,
21-
Win32::{Foundation::*, System::Com::*, UI::Accessibility::*},
21+
Win32::{
22+
Foundation::*,
23+
System::{Com::*, Variant::*},
24+
UI::Accessibility::*,
25+
},
2226
};
2327

2428
use crate::{
@@ -768,8 +772,7 @@ impl IRawElementProviderFragment_Impl for PlatformNode_Impl {
768772
fn FragmentRoot(&self) -> Result<IRawElementProviderFragmentRoot> {
769773
self.with_tree_state(|state| {
770774
if self.is_root(state) {
771-
// SAFETY: We know &self is inside a full COM implementation.
772-
unsafe { self.cast() }
775+
Ok(self.to_interface())
773776
} else {
774777
let root_id = state.root_id();
775778
Ok(self.relative(root_id).into())
@@ -850,15 +853,14 @@ macro_rules! patterns {
850853
), (
851854
$($extra_trait_method:item),*
852855
))),+) => {
853-
impl PlatformNode {
856+
impl PlatformNode_Impl {
854857
fn pattern_provider(&self, pattern_id: UIA_PATTERN_ID) -> Result<IUnknown> {
855858
self.resolve(|node| {
856859
let wrapper = NodeWrapper(&node);
857860
match pattern_id {
858861
$($pattern_id => {
859862
if wrapper.$is_supported() {
860-
// SAFETY: We know we're running inside a full COM implementation.
861-
let intermediate: $provider_interface = unsafe { self.cast() }?;
863+
let intermediate: $provider_interface = self.to_interface();
862864
return intermediate.cast();
863865
}
864866
})*
@@ -1031,7 +1033,7 @@ patterns! {
10311033
Ok(std::ptr::null_mut())
10321034
},
10331035

1034-
fn RangeFromChild(&self, _child: Option<&IRawElementProviderSimple>) -> Result<ITextRangeProvider> {
1036+
fn RangeFromChild(&self, _child: Ref<IRawElementProviderSimple>) -> Result<ITextRangeProvider> {
10351037
// We don't support embedded objects in text.
10361038
Err(not_implemented())
10371039
},

platforms/windows/src/subclass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl SubclassImpl {
9797
SetPropW(
9898
self.hwnd,
9999
PROP_NAME,
100-
HANDLE(self as *const SubclassImpl as _),
100+
Some(HANDLE(self as *const SubclassImpl as _)),
101101
)
102102
}
103103
.unwrap();

platforms/windows/src/tests/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
9191
unsafe { DefWindowProcW(window, message, wparam, lparam) }
9292
}
9393
WM_PAINT => {
94-
unsafe { ValidateRect(window, None) }.unwrap();
94+
unsafe { ValidateRect(Some(window), None) }.unwrap();
9595
LRESULT(0)
9696
}
9797
WM_DESTROY => {
@@ -142,6 +142,7 @@ fn create_window(
142142
activation_handler: Box::new(activation_handler),
143143
action_handler: Arc::new(ActionHandlerWrapper::new(action_handler)),
144144
});
145+
let module = HINSTANCE::from(unsafe { GetModuleHandleW(None)? });
145146

146147
let window = unsafe {
147148
CreateWindowExW(
@@ -155,7 +156,7 @@ fn create_window(
155156
CW_USEDEFAULT,
156157
None,
157158
None,
158-
GetModuleHandleW(None).unwrap(),
159+
Some(module),
159160
Some(Box::into_raw(create_params) as _),
160161
)?
161162
};
@@ -213,7 +214,7 @@ where
213214
}
214215

215216
let mut message = MSG::default();
216-
while unsafe { GetMessageW(&mut message, HWND::default(), 0, 0) }.into() {
217+
while unsafe { GetMessageW(&mut message, None, 0, 0) }.into() {
217218
let _ = unsafe { TranslateMessage(&message) };
218219
unsafe { DispatchMessageW(&message) };
219220
}
@@ -230,7 +231,7 @@ where
230231
};
231232

232233
let _window_guard = scopeguard::guard((), |_| {
233-
unsafe { PostMessageW(window.0, WM_CLOSE, WPARAM(0), LPARAM(0)) }.unwrap()
234+
unsafe { PostMessageW(Some(window.0), WM_CLOSE, WPARAM(0), LPARAM(0)) }.unwrap()
234235
});
235236

236237
// We must initialize COM before creating the UIA client. The MTA option
@@ -326,7 +327,7 @@ impl FocusEventHandler {
326327

327328
#[allow(non_snake_case)]
328329
impl IUIAutomationFocusChangedEventHandler_Impl for FocusEventHandler_Impl {
329-
fn HandleFocusChangedEvent(&self, sender: Option<&IUIAutomationElement>) -> Result<()> {
330+
fn HandleFocusChangedEvent(&self, sender: Ref<IUIAutomationElement>) -> Result<()> {
330331
self.received.put(sender.unwrap().clone());
331332
Ok(())
332333
}

platforms/windows/src/text.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use accesskit_consumer::{
1212
use std::sync::{Arc, RwLock, Weak};
1313
use windows::{
1414
core::*,
15-
Win32::{Foundation::*, System::Com::*, UI::Accessibility::*},
15+
Win32::{
16+
System::{Com::*, Variant::*},
17+
UI::Accessibility::*,
18+
},
1619
};
1720

1821
use crate::{context::Context, node::PlatformNode, util::*};
@@ -328,8 +331,8 @@ impl ITextRangeProvider_Impl for PlatformRange_Impl {
328331
Ok(self.this.clone().into())
329332
}
330333

331-
fn Compare(&self, other: Option<&ITextRangeProvider>) -> Result<BOOL> {
332-
let other = unsafe { required_param(other)?.as_impl() };
334+
fn Compare(&self, other: Ref<ITextRangeProvider>) -> Result<BOOL> {
335+
let other = unsafe { required_param(&other)?.as_impl() };
333336
Ok((self.context.ptr_eq(&other.context)
334337
&& *self.state.read().unwrap() == *other.state.read().unwrap())
335338
.into())
@@ -338,10 +341,10 @@ impl ITextRangeProvider_Impl for PlatformRange_Impl {
338341
fn CompareEndpoints(
339342
&self,
340343
endpoint: TextPatternRangeEndpoint,
341-
other: Option<&ITextRangeProvider>,
344+
other: Ref<ITextRangeProvider>,
342345
other_endpoint: TextPatternRangeEndpoint,
343346
) -> Result<i32> {
344-
let other = unsafe { required_param(other)?.as_impl() };
347+
let other = unsafe { required_param(&other)?.as_impl() };
345348
if std::ptr::eq(other as *const _, &self.this as *const _) {
346349
// Comparing endpoints within the same range can be done
347350
// safely without upgrading the range. This allows ATs
@@ -531,10 +534,10 @@ impl ITextRangeProvider_Impl for PlatformRange_Impl {
531534
fn MoveEndpointByRange(
532535
&self,
533536
endpoint: TextPatternRangeEndpoint,
534-
other: Option<&ITextRangeProvider>,
537+
other: Ref<ITextRangeProvider>,
535538
other_endpoint: TextPatternRangeEndpoint,
536539
) -> Result<()> {
537-
let other = unsafe { required_param(other)?.as_impl() };
540+
let other = unsafe { required_param(&other)?.as_impl() };
538541
self.require_same_context(other)?;
539542
// We have to obtain the tree state and ranges manually to avoid
540543
// lifetime issues, and work with the two locks in a specific order

platforms/windows/src/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Write for WideString {
3838

3939
impl From<WideString> for BSTR {
4040
fn from(value: WideString) -> Self {
41-
Self::from_wide(&value.0).unwrap()
41+
Self::from_wide(&value.0)
4242
}
4343
}
4444

@@ -199,8 +199,8 @@ pub(crate) fn invalid_arg() -> Error {
199199
E_INVALIDARG.into()
200200
}
201201

202-
pub(crate) fn required_param<T>(param: Option<&T>) -> Result<&T> {
203-
param.map_or_else(|| Err(invalid_arg()), Ok)
202+
pub(crate) fn required_param<'a, T: Interface>(param: &'a Ref<T>) -> Result<&'a T> {
203+
param.ok().map_err(|_| invalid_arg())
204204
}
205205

206206
pub(crate) fn element_not_available() -> Error {
@@ -248,7 +248,7 @@ pub(crate) fn window_title(hwnd: WindowHandle) -> Option<BSTR> {
248248
}
249249
let len = result.0 as usize;
250250
unsafe { buffer.set_len(len) };
251-
Some(BSTR::from_wide(&buffer).unwrap())
251+
Some(BSTR::from_wide(&buffer))
252252
}
253253

254254
pub(crate) fn toolkit_description(state: &TreeState) -> Option<WideString> {

0 commit comments

Comments
 (0)