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

Feature request: Win32 IEnumVARIANT iterator for collections #2260

Closed
aquacash5 opened this issue Dec 26, 2022 · 3 comments
Closed

Feature request: Win32 IEnumVARIANT iterator for collections #2260

aquacash5 opened this issue Dec 26, 2022 · 3 comments
Labels
question Further information is requested

Comments

@aquacash5
Copy link
Contributor

Motivation

This makes it easier to iterate though Win32 collections (eg INetFwRules, INetFwServices, ...)

Drawbacks

At the current time, it seems that the Windows projection does not mark what structs support this kind of operation, so it would be a manual process of determining which structures this can be implemented on.

Rationale and alternatives

It could be implemented as a separate library, but it would mean that the implementation wont be-able to use the IntoIterator trait on the objects directly

Additional context

I have created an iterator for this kind of object. I am using it to iterate over the INetFwRules.

pub struct IEnumIterator<T: Interface>(IEnumVARIANT, PhantomData<T>);

impl<T: Interface> IEnumIterator<T> {
    fn new(i_enum: IEnumVARIANT) -> IEnumIterator<T> {
        IEnumIterator(i_enum, PhantomData)
    }
}

impl<T: Interface> Iterator for IEnumIterator<T> {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        unsafe {
            let mut c_fetched: u32 = u32::default();
            let mut var = VARIANT::default();
            self.0
                .Next(slice::from_mut(&mut var), &mut c_fetched)
                .ok()
                .ok()?;
            VariantChangeType(&mut var, &var, 0, VT_DISPATCH).ok()?;
            let dispatch = var.Anonymous.Anonymous.Anonymous.pdispVal.as_ref();
            dispatch.and_then(|d| d.cast().ok())
        }
    }
}
@aquacash5 aquacash5 added the enhancement New feature or request label Dec 26, 2022
@kennykerr
Copy link
Collaborator

Seems like a reasonable addition but would require me to finally get to #539. 😊

@kennykerr
Copy link
Collaborator

And there are of course many COM interfaces that follow the IEnumXxx pattern that could be well served by an Iterator implementation. Ideally, any solution here would need to cover all or most of them generically.

@kennykerr
Copy link
Collaborator

Just reviewing this old issue - we now have first class support for VARIANT and PROPVARIANT in windows-core (#2786) but there isn't enough metadata to generally support iteration of IEnumXxx interfaces due to all of the unique or individual semantics from one enumeration interface to another and I'm reluctant to hand-author Iterator for each one in the windows crate as that doesn't scale.

@kennykerr kennykerr added question Further information is requested and removed enhancement New feature or request labels Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants