microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.23k stars 475 forks source link

Error when implementing a COM interface #3156

Closed leexgone closed 1 month ago

leexgone commented 1 month ago

Summary

#[implement] can't work after updated from windows 0.57.0 to windwos 0.58.0.

error[E0277]: the trait bound `MyEvent_Impl: IUIAutomationEventHandler_Impl` is not satisfied
    --> src/main.rs:24:1
     |
24   | #[implement(IUIAutomationEventHandler)]
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IUIAutomationEventHandler_Impl` is not implemented for `MyEvent_Impl`
     |
     = help: the trait `IUIAutomationEventHandler_Impl` is implemented for `MyEvent`
note: required by a bound in `IUIAutomationEventHandler_Vtbl::new`
    --> C:\Users\leexg\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.58.0\src\Windows\Win32\UI\Accessibility\impl.rs:7477:19
     |
7475 |     pub const fn new<Identity: windows_core::IUnknownImpl, const OFFSET: isize>() -> IUIAutomationEventHandler_Vtbl
     |                  --- required by a bound in this associated function
7476 |     where
7477 |         Identity: IUIAutomationEventHandler_Impl,
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `IUIAutomationEventHandler_Vtbl::new`
     = note: this error originates in the attribute macro `implement` (in Nightly builds, run with -Z macro-backtrace for more info)

Crate manifest

[package]
name = "impl_test"
version = "0.1.0"
edition = "2021"

[dependencies.windows]
version = "0.58.0"
features = [
    "implement",
    "Win32_System_Com",
    "Win32_UI_Accessibility",
    "Win32_System_Ole",
    "UI_UIAutomation",
]

[dependencies.windows-core]
version = "0.58.0"

Crate code

use windows::core::implement;
use windows::core::Result;
use windows::Win32::System::Com::CoCreateInstance;
use windows::Win32::System::Com::CoInitializeEx;
use windows::Win32::System::Com::CLSCTX_ALL;
use windows::Win32::System::Com::COINIT_MULTITHREADED;
use windows::Win32::UI::Accessibility::CUIAutomation;
use windows::Win32::UI::Accessibility::IUIAutomation;
use windows::Win32::UI::Accessibility::IUIAutomationEventHandler;
use windows::Win32::UI::Accessibility::IUIAutomationEventHandler_Impl;

fn main() -> Result<()> {
    unsafe {
        CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;

        let auto: IUIAutomation = CoCreateInstance(&CUIAutomation, None, CLSCTX_ALL)?;

        // let handler: IUIAutomationEventHandler

        Ok(())
    }
}

#[implement(IUIAutomationEventHandler)]
pub struct MyEvent();

impl IUIAutomationEventHandler_Impl for MyEvent {
    fn HandleAutomationEvent(&self,sender:Option<&windows::Win32::UI::Accessibility::IUIAutomationElement>,eventid:windows::Win32::UI::Accessibility::UIA_EVENT_ID) -> windows::core::Result<()> {
        todo!()
    }
}
kennykerr commented 1 month ago

This is a necessary breaking change introduced in #3065 - the fix is fortunately simple enough.

Zerowalker commented 1 month ago

Do you actually need to add the windows-core dependency now along with windows?

leexgone commented 1 month ago

Yes, the windows-core still needs to be dependent along with windows.

@.***

From: Zerowalker Date: 2024-07-12 17:03 To: microsoft/windows-rs CC: Steven Lee; Author Subject: Re: [microsoft/windows-rs] Error when implementing a COM interface (Issue #3156) Do you actually need to add the windows-core dependency now along with windows? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>