Skip to content

Commit

Permalink
Correct compose offset in implement macro (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Apr 28, 2022
1 parent e518d03 commit 4c0860b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ pub fn implement(attributes: proc_macro::TokenStream, original_type: proc_macro:
impl <#constraints> ::windows::core::Compose for #original_ident::<#(#generics,)*> {
unsafe fn compose<'a>(implementation: Self) -> (::windows::core::IInspectable, &'a mut ::core::option::Option<::windows::core::IInspectable>) {
let inspectable: ::windows::core::IInspectable = implementation.into();
let this = (&inspectable as *const _ as *mut ::windows::core::RawPtr).sub(1) as *mut #impl_ident::<#(#generics,)*>;
let this: ::windows::core::RawPtr = ::core::mem::transmute_copy(&inspectable);
let this = (this as *mut ::windows::core::RawPtr).sub(1) as *mut #impl_ident::<#(#generics,)*>;
(inspectable, &mut (*this).base)
}
}
Expand Down
12 changes: 9 additions & 3 deletions crates/samples/xaml_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ use windows::{
};

#[implement(IApplicationOverrides)]
struct MyApp();
struct MyApp {
text: &'static str,
placeholder: &'static str,
}

impl IApplicationOverrides_Impl for MyApp {
fn OnLaunched(&self, _: &Option<LaunchActivatedEventArgs>) -> Result<()> {
let window = Window::Current()?;
window.SetContent(TextBox::new()?)?;
let text_box = TextBox::new()?;
text_box.SetText(self.text)?;
text_box.SetPlaceholderText(self.placeholder)?;
window.SetContent(text_box)?;
window.Activate()
}
}
Expand All @@ -35,7 +41,7 @@ fn main() -> Result<()> {
}

Application::Start(ApplicationInitializationCallback::new(|_| {
Application::compose(MyApp())?;
Application::compose(MyApp { text: "Hello world", placeholder: "What are you going to build today?" })?;
Ok(())
}))
}

0 comments on commit 4c0860b

Please sign in to comment.