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

WIL for Rust #308

Closed
DrusTheAxe opened this issue Aug 6, 2020 · 10 comments
Closed

WIL for Rust #308

DrusTheAxe opened this issue Aug 6, 2020 · 10 comments
Labels
question Further information is requested

Comments

@DrusTheAxe
Copy link
Member

WIL is an invaluable library for Windows development using C++. Is there a Rust equivalent?

RAII helpers for Windows APIs like in win32_helpers.h, token_helpers.h and more would be welcome for Windows development using Rust. A 'WIL for Rust' moral equivalent or 'port to Rust language and idioms, to bring the same productivity gains to Rust as WIL brings to C++ development.

@kennykerr kennykerr added the question Further information is requested label Aug 6, 2020
@kennykerr
Copy link
Collaborator

kennykerr commented Aug 6, 2020

Thanks Howard. While I agree that there's value to having something like WIL For Rust developers, I'm not sure that it belongs in a single Rust crate. It's more likely that a family of crates will provide useful wrappers for individual Win32 APIs. We may also find that some are unnecessary depending on what overlap exists in Rust's standard library and many such crates may already exist. On the other hand, perhaps we just need a neat collection of Windows-specific helpers in a single crate for systems programming on Windows.

@tim-weis
Copy link
Contributor

tim-weis commented Aug 8, 2020

There are two crates that attempt to provide safe wrappers that I'm aware of:

wio is published by Peter Atashian, maintainer of the winapi crate, and winapi-util by Andrew Gallant. Both authors are very capable, yet neither crate is anywhere near complete, nor do they show any significant signs of life.

@kennykerr
Copy link
Collaborator

Closing as this is not specific to the Rust language projection. Feel free to keep the conversation going.

@DrusTheAxe
Copy link
Member Author

@kennykerr Fair enough. I have no preference over the form. Just interested to see the relevant functionality also available to Rust developers. Is there a better venue for that discussion?

@kennykerr
Copy link
Collaborator

I'll create a dedicated repo and link to it here.

@justanotheranonymoususer

I was also looking for something like WIL for rust. The closest thing I found is https://github.com/rodrigocfd/winsafe. It's great, but it's a single-man effort for a huge scope, it'd be great to have Microsoft to maintain/invest in such a project.

@kennykerr
Copy link
Collaborator

Many such helpers are now available including windows-core with rich COM support, windows-registry with safe and efficient registry access, windows-result with all kinds of error handling support, windows-strings that provides a bridge between Windows and Rust string types, windows-version with reliable version information, and more is on the way.

There's also support for automatically freeing various handle types akin to WIL wrappers (#3013).

@justanotheranonymoususer

@kennykerr thanks, that's good progress, keep it up! All of it looks really good, I just needed to do some registry operations and looked for a good wrapper. But it seems very simplistic, for example, in my use case I need to pass KEY_WOW64_64KEY , is that possible? Should I create an issue?

Also, like in WIL, it'd be great to be able to have a lib to take care of APIs which return variable-length strings:
https://github.com/microsoft/wil/wiki/Win32-helpers#predefined-adapters-for-functions-that-return-variable-length-strings

@kennykerr
Copy link
Collaborator

I need to pass KEY_WOW64_64KEY , is that possible? Should I create an issue?

Feel free to create an issue, otherwise I'll forget. 😊

@justanotheranonymoususer

Created, thanks. Here's another example that I encountered recently: using TaskDialogIndirect. You have an example for it here:

TaskDialogIndirect(&config, Some(&mut selection), None, None)?;

Note how the whole code is unsafe and the callback must be extern "system". Compare it to the winsafe version:

use winsafe::{self as w, prelude::*, co};

w::TaskDialogIndirect(&w::TASKDIALOGCONFIG {
    common_buttons: co::TDCBF::OK,
    window_title: Some("Title"),
    content: Some("Content"),
    callback: Some(Box::new(|hwnd: &w::HWND, tdn: w::Tdn| -> co::HRESULT {
        match tdn {
            w::Tdn::Created => println!("created"),
            _ => {},
        }
        co::HRESULT::S_OK
    })),
    ..Default::default()
})?;

Safe, typed, beautiful, with a native lambda which can capture variables etc. Is something like this in scope for this repo?

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

4 participants