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

FreeMibTable returns ERROR_INVALID_FUNCTION #1741

Closed
stormshield-kg opened this issue Nov 21, 2023 · 2 comments
Closed

FreeMibTable returns ERROR_INVALID_FUNCTION #1741

stormshield-kg opened this issue Nov 21, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@stormshield-kg
Copy link

Summary

The windows::Win32::NetworkManagement::IpHelper::FreeMibTable function frees the memory correctly, but always returns an error:

thread 'main' panicked at src\main.rs:12:41:
called `Result::unwrap()` on an `Err` value: Error { code: HRESULT(0x80070001), message: "Incorrect function." }

It seems that the function return void in the C API, but the wrapper in windows-rs returns a Result:
https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-freemibtable
https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getunicastipaddresstable#examples

Crate manifest

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

[dependencies]
windows = { version = "0.52.0", features = [
    "Win32_NetworkManagement_IpHelper",
    "Win32_Foundation",
    "Win32_NetworkManagement_Ndis",
    "Win32_Networking_WinSock",
] }

Crate code

use windows::Win32::{
    NetworkManagement::IpHelper::{
        FreeMibTable, GetUnicastIpAddressTable, MIB_UNICASTIPADDRESS_TABLE,
    },
    Networking::WinSock::AF_UNSPEC,
};

fn main() {
    unsafe {
        let mut ip_table_ptr: *mut MIB_UNICASTIPADDRESS_TABLE = std::ptr::null_mut();
        GetUnicastIpAddressTable(AF_UNSPEC, &mut ip_table_ptr as *mut _).unwrap();
        FreeMibTable(ip_table_ptr as _).unwrap();
    }
}
@stormshield-kg stormshield-kg added the bug Something isn't working label Nov 21, 2023
@kennykerr
Copy link
Contributor

FreeMibTable should return void but the Win32 metadata indicates that it returns an error code. I'll transfer this this issue for their consideration.

@kennykerr kennykerr transferred this issue from microsoft/windows-rs Nov 21, 2023
@stormshield-kg
Copy link
Author

Also applicable to windows::Windows::Win32::NetworkManagement::IpHelper::FreeInterfaceDnsSettings, and maybe other functions.

@mikebattista mikebattista self-assigned this Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants