Created
August 18, 2023 17:04
-
-
Save kennykerr/3d1a47d5f0538ef86cb95650c16c79c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies.windows] | |
version = "0.51" | |
features = [ | |
"implement", | |
"Win32_Foundation", | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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