diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf3b52..48e4f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -199,3 +199,7 @@ ## v0.13.4 + Add get_(cached)_heading_level and is_(cached)_dialog. [#92](https://github.com/leexgone/uiautomation-rs/pull/92) + +## v0.14.0 + ++ update to `windows v0.59.0`. diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 2b72d6a..e21d756 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation" -version = "0.13.4" +version = "0.14.0" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -27,13 +27,13 @@ log = ["dep:log"] chrono = "0.4.39" # phf = { version = "0.11.2", features = ["macros"] } log = { version = "0.4.22", optional = true } -uiautomation_derive = { version = "0.3.12", path = "../uiautomation_derive" } +uiautomation_derive = { version = "0.3.13", path = "../uiautomation_derive" } [dependencies.windows-core] -version = "0.58.0" +version = "0.59.0" [dependencies.windows] -version = "0.58.0" +version = "0.59.0" features = [ "Win32_Foundation", "Win32_System_Variant", @@ -46,5 +46,5 @@ features = [ "Win32_Security", "Win32_UI_Shell_PropertiesSystem", "UI_UIAutomation", - "implement", + # "implement", ] diff --git a/crates/uiautomation/src/controls.rs b/crates/uiautomation/src/controls.rs index 831d6c6..8ada49d 100644 --- a/crates/uiautomation/src/controls.rs +++ b/crates/uiautomation/src/controls.rs @@ -1988,7 +1988,7 @@ impl WindowControl { pub fn set_foregrand(&self) -> Result { let hwnd = self.control.get_native_window_handle()?; let ret = unsafe { - SetForegroundWindow(hwnd) + SetForegroundWindow(hwnd.into()) }; Ok(ret.as_bool()) } diff --git a/crates/uiautomation/src/core.rs b/crates/uiautomation/src/core.rs index 09f5da5..99ee247 100644 --- a/crates/uiautomation/src/core.rs +++ b/crates/uiautomation/src/core.rs @@ -109,7 +109,7 @@ impl UIAutomation { /// Retrieves a UI Automation element for the specified window. pub fn element_from_handle(&self, hwnd: Handle) -> Result { let element = unsafe { - self.automation.ElementFromHandle(hwnd)? + self.automation.ElementFromHandle(hwnd.into())? }; Ok(UIElement::from(element)) @@ -118,7 +118,7 @@ impl UIAutomation { /// Retrieves a UI Automation element for the specified window, prefetches the requested properties and control patterns, and stores the prefetched items in the cache. pub fn element_from_handle_build_cache(&self, hwnd: Handle, cache_request: &UICacheRequest) -> Result { let element = unsafe { - self.automation.ElementFromHandleBuildCache(hwnd, cache_request)? + self.automation.ElementFromHandleBuildCache(hwnd.into(), cache_request)? }; Ok(element.into()) } @@ -306,9 +306,9 @@ impl UIAutomation { pub fn create_property_condition(&self, property: UIProperty, value: Variant, flags: Option) -> Result { let condition = unsafe { if let Some(flags) = flags { - self.automation.CreatePropertyConditionEx(property.into(), value, flags.into())? + self.automation.CreatePropertyConditionEx(property.into(), value.as_ref(), flags.into())? } else { - self.automation.CreatePropertyCondition(property.into(), value)? + self.automation.CreatePropertyCondition(property.into(), value.as_ref())? } }; Ok(condition.into()) diff --git a/crates/uiautomation/src/dialogs.rs b/crates/uiautomation/src/dialogs.rs index cb409fa..e399469 100644 --- a/crates/uiautomation/src/dialogs.rs +++ b/crates/uiautomation/src/dialogs.rs @@ -97,6 +97,6 @@ pub fn message_box(text: &str, caption: &str, styles: MESSAGEBOX_STYLE) -> MESSA unsafe { let hwnd = GetActiveWindow(); - MessageBoxW(hwnd, lptext, lpcaption, styles) + MessageBoxW(hwnd.into(), lptext, lpcaption, styles) } } \ No newline at end of file diff --git a/crates/uiautomation/src/errors.rs b/crates/uiautomation/src/errors.rs index e827849..8727fd0 100644 --- a/crates/uiautomation/src/errors.rs +++ b/crates/uiautomation/src/errors.rs @@ -1,4 +1,6 @@ use std::fmt::Display; +use std::string::FromUtf16Error; +use std::string::FromUtf8Error; use windows::Win32::Foundation::GetLastError; use windows::core::HRESULT; @@ -39,18 +41,6 @@ impl Error { pub fn last_os_error() -> Error { let error = unsafe { GetLastError() }; - // let code: i32 = if (error.0 as i32) < 0 { - // error.0 as _ - // } else { - // ((error.0 & 0x0000FFFF) | 0x80070000) as _ - // }; - - // HRESULT(code).into() - // if let Err(e) = error { - // e.into() - // } else { - // HRESULT(0).into() - // } let result = HRESULT::from_win32(error.0); result.into() } @@ -92,11 +82,6 @@ impl From for Error { impl Into for Error { fn into(self) -> windows::core::Error { - // if self.code < 0 { - // windows::core::Error::new(HRESULT(self.code), self.message) - // } else { - // windows::core::Error::new(E_FAIL, self.message) - // } if let Some(result) = self.result() { windows::core::Error::from_hresult(result) } else { @@ -132,4 +117,16 @@ impl From<&str> for Error { } } +impl From for Error { + fn from(value: FromUtf8Error) -> Self { + value.to_string().into() + } +} + +impl From for Error { + fn from(value: FromUtf16Error) -> Self { + value.to_string().into() + } +} + pub type Result = core::result::Result; diff --git a/crates/uiautomation/src/events/functions.rs b/crates/uiautomation/src/events/functions.rs index 0a4de00..fa76c58 100644 --- a/crates/uiautomation/src/events/functions.rs +++ b/crates/uiautomation/src/events/functions.rs @@ -26,8 +26,8 @@ pub struct AutomationEventHandler { } impl IUIAutomationEventHandler_Impl for AutomationEventHandler_Impl { - fn HandleAutomationEvent(&self, sender: Option<&IUIAutomationElement>, eventid: UIA_EVENT_ID) -> windows_core::Result<()> { - if let Some(e) = sender { + fn HandleAutomationEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>, eventid: UIA_EVENT_ID) -> windows_core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); let handler = &self.handler; handler(&element, eventid.into()).map_err(|e| e.into()) @@ -51,8 +51,8 @@ pub struct AutomationPropertyChangedEventHandler { } impl IUIAutomationPropertyChangedEventHandler_Impl for AutomationPropertyChangedEventHandler_Impl { - fn HandlePropertyChangedEvent(&self, sender: Option<&IUIAutomationElement>, propertyid: UIA_PROPERTY_ID, newvalue: &windows_core::VARIANT) -> windows_core::Result<()> { - if let Some(e) = sender { + fn HandlePropertyChangedEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>, propertyid: UIA_PROPERTY_ID, newvalue: &windows::Win32::System::Variant::VARIANT) -> windows_core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); let value = Variant::from(newvalue); let handler = &self.handler; @@ -77,8 +77,8 @@ pub struct AutomationStructureChangedEventHandler { } impl IUIAutomationStructureChangedEventHandler_Impl for AutomationStructureChangedEventHandler_Impl { - fn HandleStructureChangedEvent(&self, sender: Option<&IUIAutomationElement>, changetype: windows::Win32::UI::Accessibility::StructureChangeType, runtimeid: *const windows::Win32::System::Com::SAFEARRAY) -> windows_core::Result<()> { - if let Some(e) = sender { + fn HandleStructureChangedEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>, changetype: windows::Win32::UI::Accessibility::StructureChangeType, runtimeid: *const windows::Win32::System::Com::SAFEARRAY) -> windows_core::Result<()> { + if let Some(e) = sender.as_ref() { let handler = &self.handler; let element = UIElement::from(e); let arr = SafeArray::from(runtimeid); @@ -112,8 +112,8 @@ pub struct AutomationFocusChangedEventHandler { } impl IUIAutomationFocusChangedEventHandler_Impl for AutomationFocusChangedEventHandler_Impl { - fn HandleFocusChangedEvent(&self, sender: Option<&IUIAutomationElement>) -> windows_core::Result<()> { - if let Some(e) = sender { + fn HandleFocusChangedEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>) -> windows_core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); let handler = &self.handler; handler(&element).map_err(|e| e.into()) diff --git a/crates/uiautomation/src/events/handlers.rs b/crates/uiautomation/src/events/handlers.rs index ee33596..c889dcc 100644 --- a/crates/uiautomation/src/events/handlers.rs +++ b/crates/uiautomation/src/events/handlers.rs @@ -26,8 +26,8 @@ pub struct AutomationEventHandler { } impl IUIAutomationEventHandler_Impl for AutomationEventHandler_Impl { - fn HandleAutomationEvent(&self, sender: Option<&IUIAutomationElement>, eventid: UIA_EVENT_ID) -> windows::core::Result<()> { - if let Some(e) = sender { + fn HandleAutomationEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>, eventid: UIA_EVENT_ID) -> windows::core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); self.handler.handle(&element, eventid.into()).map_err(|e| e.into()) } else { @@ -50,8 +50,8 @@ pub struct AutomationPropertyChangedHandler { } impl IUIAutomationPropertyChangedEventHandler_Impl for AutomationPropertyChangedHandler_Impl { - fn HandlePropertyChangedEvent(&self, sender: Option<&IUIAutomationElement>, propertyid: UIA_PROPERTY_ID, newvalue: &windows::core::VARIANT) -> windows::core::Result<()> { - if let Some(e) = sender { + fn HandlePropertyChangedEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>, propertyid: UIA_PROPERTY_ID, newvalue: &windows::Win32::System::Variant::VARIANT) -> windows::core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); let value = Variant::from(newvalue); self.handler.handle(&element, propertyid.into(), value).map_err(|e| e.into()) @@ -75,8 +75,8 @@ pub struct AutomationStructureChangedEventHandler { } impl IUIAutomationStructureChangedEventHandler_Impl for AutomationStructureChangedEventHandler_Impl { - fn HandleStructureChangedEvent(&self, sender: Option<&IUIAutomationElement>, changetype: windows::Win32::UI::Accessibility::StructureChangeType, runtimeid: *const windows::Win32::System::Com::SAFEARRAY) -> windows_core::Result<()> { - if let Some(e) = sender { + fn HandleStructureChangedEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>, changetype: windows::Win32::UI::Accessibility::StructureChangeType, runtimeid: *const windows::Win32::System::Com::SAFEARRAY) -> windows_core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); let arr = SafeArray::from(runtimeid); let ret = if arr.is_null() { @@ -109,8 +109,8 @@ pub struct AutomationFocusChangedEventHandler { } impl IUIAutomationFocusChangedEventHandler_Impl for AutomationFocusChangedEventHandler_Impl { - fn HandleFocusChangedEvent(&self, sender: Option<&IUIAutomationElement>) -> windows_core::Result<()> { - if let Some(e) = sender { + fn HandleFocusChangedEvent(&self, sender: windows_core::Ref<'_, IUIAutomationElement>) -> windows_core::Result<()> { + if let Some(e) = sender.as_ref() { let element = UIElement::from(e); self.handler.handle(&element).map_err(|e| e.into()) } else { diff --git a/crates/uiautomation/src/events/mod.rs b/crates/uiautomation/src/events/mod.rs index 0fca843..40edbbc 100644 --- a/crates/uiautomation/src/events/mod.rs +++ b/crates/uiautomation/src/events/mod.rs @@ -192,7 +192,7 @@ impl UIPropertyChangedEventHandler { /// Handles a Microsoft UI Automation property-changed event. pub fn handle_property_changed_event(&self, sender: &UIElement, property_id: UIProperty, new_value: Variant) -> Result<()> { unsafe { - self.handler.HandlePropertyChangedEvent(sender, property_id.into(), new_value)? + self.handler.HandlePropertyChangedEvent(sender, property_id.into(), new_value.as_ref())? }; Ok(()) } diff --git a/crates/uiautomation/src/patterns.rs b/crates/uiautomation/src/patterns.rs index b48c67a..627a765 100644 --- a/crates/uiautomation/src/patterns.rs +++ b/crates/uiautomation/src/patterns.rs @@ -861,7 +861,7 @@ impl UIItemContainerPattern { pub fn find_item_by_property(&self, start_after: UIElement, property: UIProperty, value: Variant) -> Result { // let val: VARIANT = value.into(); let element = unsafe { - self.pattern.FindItemByProperty(start_after.as_ref(), property.into(), value)? + self.pattern.FindItemByProperty(start_after.as_ref(), property.into(), value.as_ref())? }; Ok(element.into()) @@ -2426,7 +2426,7 @@ impl UITextRange { pub fn find_attribute(&self, attr: TextAttribute, value: Variant, backward: bool) -> Result { let range = unsafe { - self.range.FindAttribute(attr.into(), value, backward)? + self.range.FindAttribute(attr.into(), value.as_ref(), backward)? }; Ok(range.into()) } diff --git a/crates/uiautomation/src/processes.rs b/crates/uiautomation/src/processes.rs index bae9a43..23a8c9d 100644 --- a/crates/uiautomation/src/processes.rs +++ b/crates/uiautomation/src/processes.rs @@ -132,7 +132,7 @@ impl Process { unsafe { CreateProcessW( app.to_pcwstr(), - cmd.to_pwstr(), + Some(cmd.to_pwstr()), None, None, true, diff --git a/crates/uiautomation/src/types.rs b/crates/uiautomation/src/types.rs index 0605aea..753744d 100644 --- a/crates/uiautomation/src/types.rs +++ b/crates/uiautomation/src/types.rs @@ -4,13 +4,13 @@ use std::fmt::Display; use uiautomation_derive::EnumConvert; use uiautomation_derive::map_as; -use windows::core::Param; +// use windows::core::Param; use windows::Win32::Foundation::HWND; use windows::Win32::Foundation::POINT; use windows::Win32::Foundation::RECT; /// A Point type stores the x and y position. -#[derive(Clone, Copy, PartialEq, Eq, Default)] +#[derive(Clone, Copy, PartialEq, Default)] pub struct Point(POINT); impl Point { @@ -43,6 +43,9 @@ impl Point { } } +impl Eq for Point { +} + impl Debug for Point { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Point").field("x", &self.0.x).field("y", &self.0.y).finish() @@ -80,7 +83,7 @@ impl AsMut for Point { } /// A Rect type stores the position and size of a rectangle. -#[derive(Clone, Copy, PartialEq, Eq, Default)] +#[derive(Clone, Copy, PartialEq, Default)] pub struct Rect(RECT); impl Rect { @@ -155,6 +158,10 @@ impl Rect { } } +impl Eq for Rect { + +} + impl Debug for Rect { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Rect").field("left", &self.0.left).field("top", &self.0.top).field("right", &self.0.right).field("bottom", &self.0.bottom).finish() @@ -228,11 +235,11 @@ impl AsRef for Handle { } } -impl Param for Handle { - unsafe fn param(self) -> windows::core::ParamValue { - windows::core::ParamValue::Owned(self.0) - } -} +// impl Param for Handle { +// unsafe fn param(self) -> windows::core::ParamValue { +// windows::core::ParamValue::Owned(self.0) +// } +// } impl From for Handle { fn from(value: isize) -> Self { diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index 7d84a31..0fc6cfa 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -1,15 +1,13 @@ use std::fmt::Display; +use std::mem::ManuallyDrop; use std::ptr::null_mut; -use windows::core::Param; -use windows::core::VARIANT; use windows::core::BSTR; use windows::core::HRESULT; use windows::core::HSTRING; use windows::core::IUnknown; use windows::core::Interface; use windows::core::PSTR; -use windows::core::imp; use windows::Win32::Foundation::DECIMAL; use windows::Win32::Foundation::VARIANT_BOOL; use windows::Win32::System::Com::*; @@ -124,29 +122,51 @@ pub struct Variant { impl Variant { /// Create a null variant. fn new_null(vt: VARENUM) -> Variant { - let mut var: imp::VARIANT = unsafe { std::mem::zeroed() }; - var.Anonymous.Anonymous.vt = vt.0; + // let mut var: imp::VARIANT = unsafe { std::mem::zeroed() }; + // var.Anonymous.Anonymous.vt = vt.0; - let variant = unsafe { VARIANT::from_raw(var) }; - - variant.into() + // let variant = unsafe { VARIANT::from_raw(var) }; + + // variant.into() + let mut val = VARIANT_0_0::default(); + val.vt = vt; + let val = VARIANT { + Anonymous: VARIANT_0 { + Anonymous: ManuallyDrop::new(val) + } + }; + val.into() } /// Create a `Variant` from `vt` and `value`. - fn new(vt: VARENUM, value: imp::VARIANT_0_0_0) -> Variant { - let mut val: imp::VARIANT = unsafe { std::mem::zeroed() }; - val.Anonymous.Anonymous.vt = vt.0; - val.Anonymous.Anonymous.Anonymous = value; - - let variant = unsafe { VARIANT::from_raw(val) }; + fn new(vt: VARENUM, value: VARIANT_0_0_0) -> Variant { + // let mut val: imp::VARIANT = unsafe { std::mem::zeroed() }; + // val.Anonymous.Anonymous.vt = vt.0; + // val.Anonymous.Anonymous.Anonymous = value; + + // let variant = unsafe { VARIANT::from_raw(val) }; + + // variant.into() + let val = VARIANT { + Anonymous: VARIANT_0 { + Anonymous: ManuallyDrop::new(VARIANT_0_0 { + vt, + Anonymous: value, + wReserved1: 0, + wReserved2: 0, + wReserved3: 0, + }) + } + }; - variant.into() + val.into() } /// Retrieve the variant type. fn vt(&self) -> VARENUM { - let val = self.value.as_raw(); - unsafe { VARENUM(val.Anonymous.Anonymous.vt) } + // let val = self.value.as_raw(); + // unsafe { VARENUM(val.Anonymous.Anonymous.vt) } + self.value.vt() } /// Retrieve the variant type as `VARENUM`. @@ -155,13 +175,15 @@ impl Variant { } /// Retrieve the data of the variant. - pub(crate) fn get_data(&self) -> &imp::VARIANT_0_0_0 { - let var = self.value.as_raw(); - unsafe { &var.Anonymous.Anonymous.Anonymous } + pub(crate) fn get_data(&self) -> &VARIANT_0_0_0 { + // let var = self.value.as_raw(); + // unsafe { &var.Anonymous.Anonymous.Anonymous } + unsafe { &self.value.Anonymous.Anonymous.Anonymous } } fn as_bool(&self) -> VARIANT_BOOL { - unsafe { VARIANT_BOOL(self.get_data().boolVal) } + // unsafe { VARIANT_BOOL(self.get_data().boolVal) } + unsafe { self.get_data().boolVal } } fn as_decimal(&self) -> DECIMAL { @@ -379,11 +401,11 @@ impl Display for Variant { } } -impl Param for Variant { - unsafe fn param(self) -> windows::core::ParamValue { - windows::core::ParamValue::Owned(self.value) - } -} +// impl Param for Variant { +// unsafe fn param(self) -> windows::core::ParamValue { +// windows::core::ParamValue::Owned(self.value) +// } +// } macro_rules! val_to_variant { ($v: expr) => { @@ -399,21 +421,21 @@ macro_rules! vec_to_variant { { let vt = VARENUM(VT_ARRAY.0 | $t.0); let arr: SafeArray = $v.try_into().unwrap(); - Variant::new(vt, imp::VARIANT_0_0_0 { parray: arr.into() }) + Variant::new(vt, VARIANT_0_0_0 { parray: arr.into() }) } }; } -macro_rules! to_decimal_imp { - ($d: expr) => { - imp::DECIMAL { - wReserved: $d.wReserved, - Anonymous1: imp::DECIMAL_0 { signscale: unsafe { $d.Anonymous1.signscale } }, - Hi32: $d.Hi32, - Anonymous2: imp::DECIMAL_1 { Lo64: unsafe { $d.Anonymous2.Lo64 } } - } - }; -} +// macro_rules! to_decimal_imp { +// ($d: expr) => { +// imp::DECIMAL { +// wReserved: $d.wReserved, +// Anonymous1: imp::DECIMAL_0 { signscale: unsafe { $d.Anonymous1.signscale } }, +// Hi32: $d.Hi32, +// Anonymous2: imp::DECIMAL_1 { Lo64: unsafe { $d.Anonymous2.Lo64 } } +// } +// }; +// } impl From for Variant { fn from(value: Value) -> Self { @@ -433,23 +455,25 @@ impl From for Variant { Value::UINT(v) => val_to_variant!(v), Value::R4(v) => val_to_variant!(v), Value::R8(v) => val_to_variant!(v), - Value::CURRENCY(v) => Variant::new(VT_CY, imp::VARIANT_0_0_0 { cyVal: imp::CY { int64: v} }), - Value::DATE(v) => Variant::new(VT_DATE, imp::VARIANT_0_0_0 { date: v }), + Value::CURRENCY(v) => Variant::new(VT_CY, VARIANT_0_0_0 { cyVal: CY { int64: v} }), + Value::DATE(v) => Variant::new(VT_DATE, VARIANT_0_0_0 { date: v }), Value::STRING(v) => val_to_variant!(BSTR::from(v)), Value::UNKNOWN(v) => val_to_variant!(v), Value::DISPATCH(v) => val_to_variant!(v), - Value::ERROR(v) => Variant::new(VT_ERROR, imp::VARIANT_0_0_0 { intVal: v.0 }), - Value::HRESULT(v) => Variant::new(VT_HRESULT, imp::VARIANT_0_0_0 { intVal: v.0 }), + Value::ERROR(v) => Variant::new(VT_ERROR, VARIANT_0_0_0 { intVal: v.0 }), + Value::HRESULT(v) => Variant::new(VT_HRESULT, VARIANT_0_0_0 { intVal: v.0 }), Value::BOOL(v) => val_to_variant!(v), Value::VARIANT(v) => { - let mut val = v.value.as_raw().clone(); - Variant::new(VT_VARIANT, imp::VARIANT_0_0_0 { pvarVal: &mut val as _ }) + let mut val = v.value.clone(); + Variant::new(VT_VARIANT, VARIANT_0_0_0 { pvarVal: &mut val as _ }) }, Value::DECIMAL(v) => { - let mut decimal = to_decimal_imp!(v); - Variant::new(VT_DECIMAL, imp::VARIANT_0_0_0 { pdecVal: &mut decimal as _ }) + // let mut decimal = to_decimal_imp!(v); + // Variant::new(VT_DECIMAL, imp::VARIANT_0_0_0 { pdecVal: &mut decimal as _ }) + let mut decimal = v; + Variant::new(VT_DECIMAL, VARIANT_0_0_0 { pdecVal: &mut decimal as _ }) }, - Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, imp::VARIANT_0_0_0 { parray: v.into() }), + Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, VARIANT_0_0_0 { parray: v.into() }), Value::ArrayBool(v) => vec_to_variant!(v, VT_BOOL), Value::ArrayR8(v) => vec_to_variant!(v, VT_R8), Value::ArrayI2(v) => vec_to_variant!(v, VT_I2), @@ -580,19 +604,22 @@ impl TryInto for &Variant { }; Ok(Value::DATE(val)) } else if vt == VT_BSTR || vt == VT_LPSTR { - let val = unsafe { BSTR::from_raw(self.get_data().bstrVal) }; - Ok(Value::STRING(val.to_string())) + // let val = unsafe { BSTR::from_raw(self.get_data().bstrVal) }; + // Ok(Value::STRING(val.to_string())) + let val = unsafe { self.get_data().bstrVal.to_string() }; + Ok(Value::STRING(val)) } else if vt == VT_LPSTR { let val = unsafe { if self.get_data().pcVal.is_null() { String::from("") } else { let lpstr = self.get_data().pcVal; - let mut end = lpstr; - while *end != 0 { - end = end.add(1); - }; - String::from_utf8_lossy(std::slice::from_raw_parts(lpstr, end.offset_from(lpstr) as _)).into() + // let mut end = lpstr; + // while *end != 0 { + // end = end.add(1); + // }; + // String::from_utf8_lossy(std::slice::from_raw_parts(lpstr, end.offset_from(lpstr) as _)).into() + lpstr.to_string()? } }; @@ -623,13 +650,14 @@ impl TryInto for &Variant { Ok(Value::HRESULT(HRESULT(val))) } else if vt == VT_BOOL { let val = unsafe { - self.get_data().__OBSOLETE__VARIANT_BOOL != 0 + self.get_data().__OBSOLETE__VARIANT_BOOL.as_bool() }; Ok(Value::BOOL(val)) } else if vt == VT_VARIANT { let val = unsafe { - let v = (*self.get_data().pvarVal).clone(); - VARIANT::from_raw(v) + // let v = (*self.get_data().pvarVal).clone(); + // VARIANT::from_raw(v) + (*self.get_data().pvarVal).clone() }; Ok(Value::VARIANT(val.into())) @@ -1469,38 +1497,38 @@ impl Default for SafeArray { } } -impl From<*mut imp::SAFEARRAY> for SafeArray { - fn from(value: *mut imp::SAFEARRAY) -> Self { - let array: *mut SAFEARRAY = unsafe { - std::mem::transmute(value) - }; - Self { - array, - owned: true - } - } -} +// impl From<*mut imp::SAFEARRAY> for SafeArray { +// fn from(value: *mut imp::SAFEARRAY) -> Self { +// let array: *mut SAFEARRAY = unsafe { +// std::mem::transmute(value) +// }; +// Self { +// array, +// owned: true +// } +// } +// } -impl From<*const imp::SAFEARRAY> for SafeArray { - fn from(value: *const imp::SAFEARRAY) -> Self { - let array: *mut SAFEARRAY = unsafe { - std::mem::transmute(value) - }; - Self { - array, - owned: false - } - } -} +// impl From<*const imp::SAFEARRAY> for SafeArray { +// fn from(value: *const imp::SAFEARRAY) -> Self { +// let array: *mut SAFEARRAY = unsafe { +// std::mem::transmute(value) +// }; +// Self { +// array, +// owned: false +// } +// } +// } -impl Into<*mut imp::SAFEARRAY> for SafeArray { - fn into(mut self) -> *mut imp::SAFEARRAY { - self.owned = false; - unsafe { - std::mem::transmute(self.array) - } - } -} +// impl Into<*mut imp::SAFEARRAY> for SafeArray { +// fn into(mut self) -> *mut imp::SAFEARRAY { +// self.owned = false; +// unsafe { +// std::mem::transmute(self.array) +// } +// } +// } impl From<*mut SAFEARRAY> for SafeArray { diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index 4d53542..6385f8e 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation_derive" -version = "0.3.12" +version = "0.3.13" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -18,6 +18,6 @@ default-target = "x86_64-pc-windows-msvc" targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] [dependencies] -syn = { version = "2.0.90", features = ["full"] } -quote = "1.0.37" +syn = { version = "2.0.95", features = ["full"] } +quote = "1.0.38" proc-macro2 = "1.0.92" diff --git a/samples/win_update/Cargo.toml b/samples/win_update/Cargo.toml index de402f9..fd6b823 100644 --- a/samples/win_update/Cargo.toml +++ b/samples/win_update/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "win-update" -version = "1.6.3" +version = "1.7.0" edition = "2021" [dependencies] diff --git a/tests/event_test/Cargo.toml b/tests/event_test/Cargo.toml index 1fc6200..bcaa8f3 100644 --- a/tests/event_test/Cargo.toml +++ b/tests/event_test/Cargo.toml @@ -7,12 +7,12 @@ edition = "2021" [dependencies] uiautomation = { path = "../../crates/uiautomation" } -windows-core = "0.58.0" +windows-core = "0.59.0" [dependencies.windows] -version = "0.58.0" +version = "0.59.0" features = [ - "implement", + # "implement", "UI_UIAutomation", "Win32_UI_Accessibility", ] diff --git a/tests/event_test/src/lib.rs b/tests/event_test/src/lib.rs index c453fff..3728fae 100644 --- a/tests/event_test/src/lib.rs +++ b/tests/event_test/src/lib.rs @@ -7,8 +7,8 @@ pub struct MyEventHandler { } impl IUIAutomationEventHandler_Impl for MyEventHandler_Impl { - fn HandleAutomationEvent(&self,sender:Option<&IUIAutomationElement>,eventid:UIA_EVENT_ID) -> windows::core::Result<()> { - if let Some(element) = sender { + fn HandleAutomationEvent(&self,sender:windows_core::Ref<'_, IUIAutomationElement>,eventid:UIA_EVENT_ID) -> windows::core::Result<()> { + if let Some(element) = sender.as_ref() { let element = UIElement::from(element); println!("event: {}, element: {}", eventid.0, element); } else {