Skip to content

Commit

Permalink
Generate QueryInterface-like helper function for callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed May 13, 2021
1 parent 7ad7655 commit 93762e2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/gen/src/types/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,24 @@ impl Callback {
quote! {}
};

let query_interface_fn = if signature.has_query_interface() {
let constraints = signature.gen_constraints(&signature.params);
let leading_params = &signature.params[..signature.params.len() - 2];
let params = signature.gen_win32_params(leading_params, gen);
let args = leading_params.iter().map(|p| p.gen_win32_abi_arg());
quote! {
pub unsafe fn #name<#constraints T: ::windows::Interface>(func: &#name, #params) -> ::windows::Result<T> {
let mut result__ = ::std::option::Option::None;
(func)(#(#args,)* &<T as ::windows::Interface>::IID, ::windows::Abi::set_abi(&mut result__)).and_some(result__)
}
}
} else {
quote!()
};

quote! {
pub type #name = unsafe extern "system" fn(#(#params),*) #return_type;
#query_interface_fn
}
}
}

0 comments on commit 93762e2

Please sign in to comment.