Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace internal IActivationFactory definition with tailored definition #1678

Merged
merged 1 commit into from
Apr 11, 2022

Conversation

kennykerr
Copy link
Collaborator

The IActivationFactory interface is implemented by all WinRT class factories and acts as the gateway for DLL-based activation. This is a curious interface whose ActivateInstance method isn't very practical for language projections to use since they almost always need to immediately cast the result to something other than what this method returns. As such, the definition used by the windows crate is different to the one provided by the generated bindings. In order to avoid name collisions, the version used internally by the factory cache is renamed to avoid this conflict. #1675 should also help to avoid such collisions in a more general way in future but is a bigger change that I'll tackle separately.

This PR also updates the test component to illustrate how components can implement IActivationFactory directly using the bindings generated by the bindgen crate rather than depending on the internal definition used by the windows crate.

Fixes #1662

@kennykerr kennykerr merged commit f004619 into master Apr 11, 2022
@kennykerr kennykerr deleted the generic_factory branch April 11, 2022 18:10
Copy link
Contributor

@rylev rylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits.

One thing to note: the actual change here is pretty small, but the diff is big because so many bindings needed to change. It would be very helpful to separate out implementation work in one commit from changes to bindings in another.

use super::*;
use std::mem::*;

// A streamlined version of the IActivationFactory interface used by WinRT class factories used internally by the windows crate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should be a /// doc comment so that it's picked up by tooling

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work when the docs are hidden for this type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-analyzer shows hidden docs so those working on Windows (who would be the ones who would benefit from this doc), would be able to see this on hover.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense. I haven't used rust-analyzer in many months as it seemed to really struggle with the size of the repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I'll try to make a habit of using /// for this purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I noticed rust-analyzer was really struggling... I was able to get it to work fine by editing the workspace definition and removing some things temporarily. This at least allowed me to use rust-analyzer from within windows::core.

pub struct IGenericFactory(IUnknown);

impl IGenericFactory {
pub fn ActivateInstance<I: Interface>(&self) -> Result<I> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is an internal API but some documentation would be helpful. Even if it just points out that this is the ActivateInstance from IActivationFactory (and then link here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get rid of hand-rolled IActivationFactory
3 participants