Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Created August 18, 2023 17:04
Show Gist options
  • Save kennykerr/3d1a47d5f0538ef86cb95650c16c79c1 to your computer and use it in GitHub Desktop.
Save kennykerr/3d1a47d5f0538ef86cb95650c16c79c1 to your computer and use it in GitHub Desktop.
[dependencies.windows]
version = "0.51"
features = [
"implement",
"Win32_Foundation",
]
#![allow(non_snake_case)]
use windows::{core::*, Win32::Foundation::*};
#[interface("17f409a1-f79d-45f6-962d-9db106cb7727")]
unsafe trait ICompositor: IUnknown {
unsafe fn CreateVisual(&self, value: u32, visual: *mut Option<IVisual>) -> HRESULT;
}
#[interface("34e49797-1302-4ad6-8975-dd7c5b286e72")]
unsafe trait IVisual: IUnknown {
unsafe fn GetValue(&self, value: *mut u32) -> HRESULT;
}
#[implement(ICompositor)]
struct Compositor;
impl ICompositor_Impl for Compositor {
unsafe fn CreateVisual(&self, value: u32, result: *mut Option<IVisual>) -> HRESULT {
let visual: IVisual = Visual(value).into();
*result = Some(visual);
S_OK
}
}
#[implement(IVisual)]
struct Visual(u32);
impl IVisual_Impl for Visual {
unsafe fn GetValue(&self, value: *mut u32) -> HRESULT {
*value = self.0;
S_OK
}
}
fn main() -> Result<()> {
unsafe {
let compositor: ICompositor = Compositor.into();
let mut visual: Option<IVisual> = None;
compositor.CreateVisual(123, &mut visual).ok()?;
if let Some(visual) = visual {
let mut value = 0;
visual.GetValue(&mut value).ok()?;
println!("value: {}", value);
}
Ok(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment