Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interface macro should implement IntoParam #1618

Closed
MolotovCherry opened this issue Mar 18, 2022 · 3 comments
Closed

interface macro should implement IntoParam #1618

MolotovCherry opened this issue Mar 18, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@MolotovCherry
Copy link

MolotovCherry commented Mar 18, 2022

Some methods have signatures like

windows::Windows::Win32::System::Wmi::IUnsecuredApartment
pub unsafe fn CreateObjectStub<'a, Param0>(&self, pobject: Param0) -> ::windows::core::Result<::windows::core::IUnknown>
where
    Param0: ::windows::core::IntoParam<'a, ::windows::core::IUnknown>,

Where the current custom interfaces defined using #[interface] cannot be sent as a parameter to this since they don't seem to implement IntoParam. It would be convenient if they implemented this so they can be easily passed to functions that require it.

Workaround isn't super difficult, something like this works
pUnsecApp.CreateObjectStub::<IUnknown>(event_sink.into())

@MolotovCherry MolotovCherry changed the title Implement IntoParam for Interfaces Implement IntoParam for custom Interfaces Mar 18, 2022
@kennykerr
Copy link
Collaborator

Yes that's missing. Thanks for the reminder. @rylev is still working on that macro.

@kennykerr kennykerr changed the title Implement IntoParam for custom Interfaces interface macro should implement IntoParam Mar 18, 2022
@kennykerr kennykerr added the enhancement New feature or request label Mar 18, 2022
@kennykerr
Copy link
Collaborator

Correction, this seems to work. Here's a complete repro:

[dependencies.windows]
version = "0.34"
features = [
    "implement",
    "interface",
    "Win32_System_WinRT",
]
use windows::{core::*, Win32::System::WinRT::*};

#[interface("bdbec94c-ae60-49e3-894f-009b1ce9af71")]
pub unsafe trait ISample: IUnknown {
    unsafe fn method(&self);
}

#[implement(ISample)]
struct Sample();

impl ISample_Impl for Sample {
    unsafe fn method(&self) {}
}

fn main() {
    let sample: ISample = Sample().into();
    unsafe {
        let _ = RoGetAgileReference(AGILEREFERENCE_DEFAULT, &IUnknown::IID, sample);
    }
}

@MolotovCherry
Copy link
Author

MolotovCherry commented Mar 18, 2022

Just saw this on Ryan's PR. My title was incorrect, I should have said #[implement()], not interface (but this point is invalid anyways, as that's not the right way to do it). That looks good 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants