Closed
Description
Summary
Define a runtimeclass with an event (e.g. OnClicked
) in an .idl file, then compile it to .winmd using midlrt.exe. Use windows-bindgen
to generate Rust projection using --implement
flag.
Expected: both OnClicked
and RemoveOnClicked
are generated
Seen: only RemoveOnClicked
is generated
Crate manifest
[package]
name = "event-test"
version = "0.1.0"
edition = "2024"
[dependencies]
[build-dependencies]
windows-bindgen = "0.61.1"
Crate code
// definition.idl
namespace Definition
{
runtimeclass ExampleClass
{
ExampleClass();
event Windows.Foundation.TypedEventHandler<ExampleClass, String> OnClicked;
}
}
// build.rs
fn main() {
println!("cargo:rerun-if-changed=definition.idl");
let metadata_dir = format!("{}\\System32\\WinMetadata", env!("windir"));
let mut command = std::process::Command::new("midlrt.exe");
command.args([
"/winrt",
"/nomidl",
"/h",
"nul",
"/metadata_dir",
&metadata_dir,
"/reference",
&format!("{metadata_dir}\\Windows.Foundation.winmd"),
"/winmd",
"definition.winmd",
"definition.idl",
]);
if !command.status().unwrap().success() {
panic!("failed to run midlrt.exe");
}
windows_bindgen::bindgen([
"--in",
"definition.winmd",
"default",
"--out",
"src/bindings.rs",
"--filter",
"Definition",
"--implement"
]);
}