contextfree / winrt-rust

Use and (eventually) make Windows Runtime APIs with Rust
Apache License 2.0
142 stars 10 forks source link

Figure out how to handle (un-)initialization of the Runtime #18

Closed Boddlnagg closed 5 years ago

Boddlnagg commented 7 years ago

In other words, provide wrappers for RoInitialize and RoUninitialize and somehow ensure that the runtime is initialized before making other calls.

Boddlnagg commented 7 years ago

To statically prevent calling any WinRT functions without having initialized the runtime correctly (or after unintialization) is quite hard, if not impossible with current Rust. It would require adding a lifetime parameter to ComPtr which binds the lifetime to a runtime context returned by the initialization function. However, adding a lifetime to ComPtr is not easily possible, because it is used as associated type (RtType::Out), such that some impls would have a lifetime parameters and some don't. I don't know if this is possible without HKT.

Boddlnagg commented 7 years ago

In #25 we panic now with an appropriate message if RoGetActivationFactory is called without being correctly initialized. It is hard to get uninitialization wrong, but if one actually uninitializes while there are still WinRT objects alive, calling methods on them can lead to memory access violations, i.e. the thing that should not happen in safe Rust.

Boddlnagg commented 5 years ago

Closing in favor of #62, where the discussion has happened more recently.