-
Notifications
You must be signed in to change notification settings - Fork 512
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
COM Interface Declaration Support #1540
Conversation
That's a great start. That's essentially what I had in mind with #1486. A few comments. Why require an We need to support two key scenarios that should be easy to test:
Something like this should validate the basic support: #![allow(non_snake_case)]
use windows::{
core::*,
Win32::Foundation::*,
Win32::System::Com::*,
};
#[interface("a39ee748-6a27-4817-a6f2-13914bef5890")]
unsafe trait ICustomUri : IUnknown {
fn GetPropertyBSTR(&self);
fn GetPropertyLength(&self);
fn GetPropertyDWORD(&self);
fn HasProperty(&self);
fn GetAbsoluteUri(&self);
fn GetAuthority(&self);
fn GetDisplayUri(&self);
fn GetDomain(&self, value: *mut BSTR) -> HRESULT;
// etc
}
#[implement(ICustomUri)]
struct CustomUri();
impl ICustomUri_Impl for CustomUri {
fn GetPropertyBSTR(&self) { todo!() }
fn GetPropertyLength(&self) { todo!() }
fn GetPropertyDWORD(&self) { todo!() }
fn HasProperty(&self) { todo!() }
fn GetAbsoluteUri(&self) { todo!() }
fn GetAuthority(&self) { todo!() }
fn GetDisplayUri(&self) { todo!() }
fn GetDomain(&self, value: *mut BSTR) -> HRESULT {
*value = "kennykerr.ca".into();
S_OK
}
}
fn main() -> windows::core::Result<()> {
unsafe {
// Use the OS implementation through the OS interface
let a: IUri = CreateUri("http://kennykerr.ca", Default::default(), 0)?;
let domain = a.GetDomain()?;
assert_eq!(domain, "kennykerr.ca");
// Call the OS implementation through the custom interface
let b: ICustomUri = a.cast()?;
let mut domain = BSTR::new();
b.GetDomain(&mut domain).ok()?;
assert_eq!(domain, "kennykerr.ca");
// Use the custom implementation through the OS interface
let c: IUri = CustomUri().into();
let domain = c.GetDomain()?;
assert_eq!(domain, "kennykerr.ca");
// Call the custom implementation through the custom interface
let d: ICustomUri = c.cast()?;
let mut domain = BSTR::new();
d.GetDomain(&mut domain).ok()?;
assert_eq!(domain, "kennykerr.ca");
Ok(())
}
} |
@kennykerr thanks for the example code! I got it working (with a few minor changes that I believe were just typos in the provided example). As for why I require I talk a bit more about this in the com-rs docs. Speaking of which, I think I should add docs on how |
🥳🥳 Awesome. Hoping to use this to write an implementation of the d3d9 interface in Rust :) Great to see this stuff from the |
This PR adds the very beginnings of COM interface declaration support.
There is still plenty of additional support to add, and many interfaces will not work yet, but I believe it's a good start, and I wanted to get feedback sooner rather than later.
Fixes #1486