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

WMI (MI_xxx) functions - where are they? #1572

Closed
vpopescu opened this issue Feb 28, 2022 · 7 comments
Closed

WMI (MI_xxx) functions - where are they? #1572

vpopescu opened this issue Feb 28, 2022 · 7 comments
Labels
question Further information is requested

Comments

@vpopescu
Copy link

It looks like the crate wraps the MI library for WMI, in namespace windows::Win32::System:Wmi. This is great, however I only see one function defined, MI_Application_InitializeV1.

At least from my exposure to this MI library via C, I would need additional functions, such as:

Is this an omission, or is the usage model different than C, and I'm missing something obvious? How would I create a MI_Session?

Ref: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/Wmi/index.html#functions

@vpopescu vpopescu changed the title WMI functions - where are they? WMI (MI_xxx) functions - where are they? Feb 28, 2022
@riverar riverar added the question Further information is requested label Feb 28, 2022
@riverar
Copy link
Collaborator

riverar commented Feb 28, 2022

Hey @vpopescu. Those functions are unfortunately header-only functions, found in mi.h. You'll have to manually use the ft member hanging off the MI_Application object that's returned after calling MI_Application_InitializeV1.

MI_INLINE MI_Result MI_Application_NewSession(
    _In_     MI_Application *application,
    ...)
{
    if (application && application->ft)
    {
        return application->ft->NewSession(application, protocol, destination, options, callbacks, extendedError, session);
    }
    // ...

Going to close this for now as it's not a crate issue, but feel free to continue the discussion or re-open if needed.

@riverar riverar closed this as completed Feb 28, 2022
@vpopescu
Copy link
Author

Depends on what the goal of the crate is. If someone is doing Rust only and had no exposure to doing this in C, how are they supposed to create WMI applications?

@riverar
Copy link
Collaborator

riverar commented Feb 28, 2022

One of the goals of the crate is to give you access to Windows APIs. MI_* APIs are not Windows APIs but rather belong to Windows Management Infrastructure (MI). Use of these APIs also requires the Windows Management Framework redistributable to be installed.

That said, I did try to write a quick sample for you but had to stop abruptly due to the unfortunate way the MI_ApplicationFT struct is represented (just a bunch of isize-d pointers). I'll file an issue on the Win32 metadata side of things to see if we can improve that so we can at least move forward. An enterprising developer will likely need to get their hands dirty here and port over/rewrite this goop. Maybe even put together a windows dependent wmi crate.

@vpopescu
Copy link
Author

Thanks for looking into it. I kinda got stuck around the same place you got stuck as well. Yes, I think it needs a little TLC, it's either unusable, or beyond my Rust skills at the moment.

I think MI has been included in the OS since Win8 (?) -- of course, with available downloadable updates.

There is a third party WMI crate (https://crates.io/crates/wmi) but I don't think it supports executing methods. However it doesn't depend on MI. It's pretty good if all you need is to read WMI.

@vpopescu
Copy link
Author

vpopescu commented Mar 7, 2022

@riverar Could you link the WIn32 metadata issue here, so we can track an open issue?

@riverar
Copy link
Collaborator

riverar commented Mar 7, 2022

@vpopescu Will do momentarily.

@CrendKing
Copy link

Hope you guys can add the functions to some crate, if not this one. Currently I have to handcraft my own function signature, then transmute the isize to function pointer.

pub type MI_Application_NewSession = extern "system" fn(
    application: *const MI_Application,
    protocol: *const u16,
    destination: *const u16,
    options: *const MI_DestinationOptions,
    callbacks: *const MI_SessionCallbacks,
    extendederror: *mut *mut MI_Instance,
    session: *mut MI_Session,
) -> MI_Result;

let mut application: MI_Application;
let mut session: MI_Session;

MI_Application_InitializeV1(0, null(), null_mut(), &mut application);
std::mem::transmute::<_, MI_Application_NewSession>((*application.ft).NewSession)(&application, null(), null(), null(), null(), null_mut(), &mut session);

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

3 participants