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

Transform BOOL and Win32 return values #2476

Merged
merged 3 commits into from
Apr 26, 2023
Merged

Transform BOOL and Win32 return values #2476

merged 3 commits into from
Apr 26, 2023

Conversation

kennykerr
Copy link
Collaborator

Currently, the windows crate will transform API functions that return HRESULT or NTSTATUS into Result<T> to provide a more idiomatic developer experience.

This update extends that transformation to functions that return WIN32_ERROR, like RegOpenKeyExW, as well as functions that return BOOL and also have metadata that indicates they call SetLastError on failure, like LookupPrivilegeNameW.

Fixes: #2467

@kennykerr
Copy link
Collaborator Author

CC @talagrand and @riverar if you'd like to spot check.

@talagrand
Copy link

talagrand commented Apr 25, 2023

Thank you @kennykerr! I spot checked all the APIs I was using and they're all covered by this PR.

Now, I can open a separate issue for this but it would be ideal if APIs that use the pattern sentinel + GetLastError() were also covered. Things like ExpandEnvironmentStringsW (returns 0 on failure) or ResumeThread (returns -1) or GlobalLock (returns NULL).

@riverar
Copy link
Collaborator

riverar commented Apr 26, 2023

Now, I can open a separate issue for this but it would be ideal if APIs that use the pattern sentinel + GetLastError() were also covered. Things like ExpandEnvironmentStringsW (returns 0 on failure) or ResumeThread (returns -1) or GlobalLock (returns NULL).

This will require additional metadata support; do file an issue at https://github.com/microsoft/win32metadata/issues thanks!

@kennykerr kennykerr merged commit 97efa32 into master Apr 26, 2023
@kennykerr kennykerr deleted the result-void branch April 26, 2023 01:33
@tim-weis tim-weis mentioned this pull request May 27, 2023
lambdalisue added a commit to lambdalisue/rs-metrics-process that referenced this pull request Aug 15, 2023
sholderbach pushed a commit to nushell/nushell that referenced this pull request Dec 21, 2023
# Description
Bump `windows` to 0.52.0 and fix `is_admin`

microsoft/windows-rs#2476

# User-Facing Changes
N/A

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Bump `windows` to 0.52.0 and fix `is_admin`

microsoft/windows-rs#2476

# User-Facing Changes
N/A

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Win32 BOOL+GetLastError() mapping to Result
3 participants