Windows-rs: Document usage of COM interfaces

Created on 4 Feb 2021  路  8Comments  路  Source: microsoft/windows-rs

Looking at IStream, the declaration does not say anything about ISequentialStream and IUnknown. The stream object is unusable without ISequentialStream methods and I also need AddRef/Release from IUnknown, is there a workaround for this?

Scenario: I'm getting a pointer of IStream via IInitializeWithStream::Initialize, keep it, and read it in IThumbnailProvider::GetThumbnail. (Source currently with winapi-rs)

documentation question

Most helpful comment

We should probably also add some docs to explicitly talk about how COM is handled. We have a two examples now using COM, but some prose that more directly explains things like QueryInterface == Interface::cast, AddRef == Clone::clone, and Release == Drop would be good to have.

All 8 comments

You can use .cast::<ISequentialStream>() which is from the windows::Interface trait that's implemented for IStream.

To use AddRef you call .clone() and Release is called once the interface is dropped (it implements the Drop trait).

I implemented COM inheritance support a short while back: https://github.com/microsoft/windows-rs/pull/448

I will publish another update to https://crates.io/ and update the documentation soon.

We should probably also add some docs to explicitly talk about how COM is handled. We have a two examples now using COM, but some prose that more directly explains things like QueryInterface == Interface::cast, AddRef == Clone::clone, and Release == Drop would be good to have.

crates.io and the Windows API documentation has now been updated. For example, you can find the IStream docs here. As you can see, it provides the ISequentialStream methods directly (as they're inherited) and provides convertibility for all base interfaces.

Cool, confirmed that ISequentialStream::Read works 馃憤

Glad to hear its working. 馃榾

Duplicate of #81

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ctaggart picture ctaggart  路  4Comments

kennykerr picture kennykerr  路  5Comments

rylev picture rylev  路  5Comments

rylev picture rylev  路  4Comments

06393993 picture 06393993  路  3Comments