-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
using Windows.Win32; | ||
using Windows.Win32.Foundation; | ||
|
||
namespace Nefarius.Utilities.DeviceManagement.Util; | ||
|
||
/// <summary> | ||
/// Utility methods for handling NTSTATUS values. | ||
/// </summary> | ||
public static class NtStatusUtil | ||
{ | ||
/// <summary> | ||
/// Converts an NTSTATUS value to a <see cref="WIN32_ERROR" />. | ||
/// </summary> | ||
/// <remarks>https://stackoverflow.com/a/32205631</remarks> | ||
/// <param name="ntStatus">The NTSTATUS value to convert.</param> | ||
/// <returns>The converted Win32 error code.</returns> | ||
public static int ConvertNtStatusToWin32Error(uint ntStatus) | ||
{ | ||
NativeOverlapped ol = new() { InternalLow = (IntPtr)ntStatus }; | ||
int oldError = Marshal.GetLastWin32Error(); | ||
PInvoke.GetOverlappedResult(null, ol, out uint _, new BOOL(false)); | ||
int result = Marshal.GetLastWin32Error(); | ||
PInvoke.SetLastError((WIN32_ERROR)oldError); | ||
return result; | ||
} | ||
} |