leexgone / uiautomation-rs

The uiatomation-rs crate is a wrapper for windows uiautomation. This crate can help you make windows uiautomation API calls conveniently.
Apache License 2.0
83 stars 15 forks source link

Crash when using `RuntimeId` in a property condition #52

Closed jelder closed 4 months ago

jelder commented 4 months ago

I'm working something where I need to discover an element through a walker, and then later interact with it by its RuntimeId. I may be using the API wrong, but the most obvious (to me) way crashes with (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION).

In the below MVBR, for simplicity sake, I'm skipping the walker and just trying to find the root element a second time using the result of root.get_runtime_id().

use uiautomation::core::UIAutomation;
use uiautomation::types::{TreeScope, UIProperty};
use uiautomation::variants::*;

fn main() {
    let automation = UIAutomation::new().unwrap();
    let root = automation.get_root_element().unwrap();
    let runtime_id = root.get_runtime_id().unwrap();

    // exit code: 0xc0000005, STATUS_ACCESS_VIOLATION occurs on next line
    let condition = automation
        .create_property_condition(
            UIProperty::RuntimeId,
            Variant::from(Value::ArrayI4(runtime_id)),
            None,
        )
        .expect("Failed to create condition");

    let element = root
        .find_first(TreeScope::Element, &condition)
        .expect("Failed to find element");

    eprintln!("{}", element.get_name().unwrap());
}
leexgone commented 4 months ago

There seems to be a problem handling the conversion of Vec to Variant. I just need some time to research this problem.

leexgone commented 4 months ago

fixed on v0.9.3