contextfree / winrt-rust

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

Some experiments with HString wrapper and ComPtr #3

Closed Boddlnagg closed 7 years ago

Boddlnagg commented 8 years ago

This is not meant to be merged!

It shows my progress so far and allows me to share it with you more easily. Note that it requires a local override of winapi-rs with the necessary changes (either my or your PR).

What is currently definitely wrong in my implementation is:

(By the way, I probably won't have much time to work on this during the next weeks.)

contextfree commented 8 years ago

Thanks! I probably won't get a chance to seriously look/work on this until Tuesday or Wednesday.

Boddlnagg commented 8 years ago

Oh, one more comment: Another reason that we probably can't rely on winapi's RIDL macro, is that we sometimes need generic definitions, e.g. IAsyncOperation<T>.

Boddlnagg commented 8 years ago

This might also be helpful: https://github.com/retep998/winapi-rs/issues/145#issuecomment-122168427. It's about how to implement a COM interface from Rust.

Boddlnagg commented 8 years ago

Also please note that my test code still requires a change in winapi: Add #[derive(PartialEq, Eq)] to GUID in guiddef.rs.

Boddlnagg commented 8 years ago

... this last commit renders my previous comment obsolete.

Boddlnagg commented 8 years ago

This is now in a state where it actually starts looking like more than a proof-of-concept. I'd like to have some feedback and then we should get started with the automatic code-generation.

I wonder if we can get rid of this out-pointer-passing in the low-level-bindings already? I think we should generate the impl for the function definitions (which forward to the vtbl) already in such a way that they 1) ... take care of creating the unitialized out-pointers for the return values, check the HRESULT and return Result<T, HRESULT> (or some custom error type) 2) ... already have a snake_case name. (As far as I understand it, language projections should map to the respective naming conventions.)

This is not possible with macros, but should easy with custom codegen, as long as we're careful with possible null return values.