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

Correct compose offset in implement macro #1724

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}))
}