microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.1k stars 473 forks source link

Can't see feature requirement for methods #3123

Closed Cinimajig closed 1 week ago

Cinimajig commented 1 week ago

Summary

I'll use INetwork::GetName as en example.

I was trying to call the above method on the INetwork interface, but it does not exist. I then looked up the function on windows-docs-rs, but I cant see what feature I'm missing to use it.

Image of windows-docs-rs

I then tried to find the interface on the feature searcher, but it does not mention methods, only the interface itself... How are we supposed to find this information?

Crate manifest

[package]
name = "networklist"
version = "0.1.0"
edition = "2021"

[profile.release]
lto = true
codegen-units = 1
strip = true

[dependencies]
windows = { version = "0.57.0", features = [
    "Win32_Foundation",
    "Win32_System_Com",
    "Win32_System_LibraryLoader",
    "Win32_UI_WindowsAndMessaging",
    "Win32_Graphics_Gdi",
    "Win32_NetworkManagement_IpHelper",
    "Win32_Networking_WinInet",
    "Win32_Networking_NetworkListManager",
] }

Crate code

fn enum_network() -> windows::core::Result<()> {
    use windows::Win32::{Networking::NetworkListManager::*, System::Com::*};

    unsafe {
        CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok()?;
        let manager: INetworkListManager = CoCreateInstance(&NetworkListManager, None, CLSCTX_ALL)?;

        let enumer = manager.GetNetworkConnections()?;

        let mut conn: [Option<INetworkConnection>; 10] = Default::default();
        let mut amount: u32 = 10;
        while let Ok(_) = enumer.Next(&mut conn, Some(&mut amount)) {
            if amount == 0 {
                break;
            }
            for connection in &conn {
                match connection {
                    Some(connection) => {
                        let network = connection.GetNetwork()?;

                        let cat = network.GetCategory()?;
                        let description = network.GetDescription()?;
                        let name = connection.GetName()?; // <-- Error here

                        println!("Network name : {}", name);
                        println!("Description  : {}", description);
                        println!("Category     : {}", cat.0);
                    }
                    None => (),
                }
            }
        }

        Ok(())
    }
}
riverar commented 1 week ago

Ah, sorry for the confusion. In this example, you will need:

    "Win32_System_Com",
    "Win32_Networking_NetworkListManager",

We're still working on the best way to expose all features required at all levels of the type hierarchy, without bloating up the docs, features index, crate, etc.

Cinimajig commented 1 week ago

But I already have that... You can see them in the Crate Manifest.

riverar commented 1 week ago

Oh my mistake, I missed your full sample!

So the error is:

error[E0599]: no method named `GetName` found for reference `&Networking::NetworkListManager::INetworkConnection` in the current scope

INetworkConnection doesn't have a GetName method. https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Networking/NetworkListManager/struct.INetworkConnection.html

riverar commented 1 week ago

Did you mean for let name = connection.GetName()?; to be let name = network.GetName()?; instead?

Cinimajig commented 1 week ago

Oh wownyeah. Totally missed that. My bad 😅

riverar commented 1 week ago

Will close this one as fixed then. Have fun!