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

Using OutRef for generated bindings #3152

Closed
lifers opened this issue Jul 8, 2024 · 3 comments
Closed

Using OutRef for generated bindings #3152

lifers opened this issue Jul 8, 2024 · 3 comments
Labels
question Further information is requested

Comments

@lifers
Copy link
Contributor

lifers commented Jul 8, 2024

Suggestion

I am trying to implement this kind of runtimeclass and was confused about how to write an out parameter from Rust.

namespace example
{
  runtimeclass Simple
  {
    Simple();
    void Repeat(UInt8 input, out IVectorView<UInt8> output);
  }
}

From #3025, I suppose using OutRef will be best. However, the generated bindings doesn't use it, and I'm not sure how to use OutRef.write() in my implementation.

...
pub trait ISimple_Impl: Sized {
    fn Repeat(
        &self,
        input: u8,
        output: &mut Option<windows::Foundation::Collections::IVectorView<u8>>,
    ) -> windows_core::Result<()>;
}
impl windows_core::RuntimeName for ISimple {
    const NAME: &'static str = "example.ISimple";
}
impl ISimple_Vtbl {
    pub const fn new<Identity: windows_core::IUnknownImpl, const OFFSET: isize>() -> ISimple_Vtbl
    where
        Identity: ISimple_Impl,
    {
        unsafe extern "system" fn Repeat<
            Identity: windows_core::IUnknownImpl,
            const OFFSET: isize,
        >(
            this: *mut core::ffi::c_void,
            input: u8,
            output: *mut *mut core::ffi::c_void,
        ) -> windows_core::HRESULT
        where
            Identity: ISimple_Impl,
        {
            let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
            ISimple_Impl::Repeat(this, input, core::mem::transmute_copy(&output)).into()
        }
...

Any advice would be appreciated. Thank you.

@lifers lifers added the enhancement New feature or request label Jul 8, 2024
@kennykerr
Copy link
Collaborator

OutRef isn't used by windows-bindgen yet but that is something that I plan to harmonize.

@kennykerr kennykerr added question Further information is requested and removed enhancement New feature or request labels Jul 9, 2024
@kennykerr
Copy link
Collaborator

In other words, for now you can just ignore OutRef and implement the trait as defined by windows-bindgen.

@kennykerr
Copy link
Collaborator

As of #3386, Ref and OutRef are used by generating bindings as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants