Added NTStatus.NTSTATUS_FROM_WIN32 function and implicit operator from Win32Error to NTStatus using that function.

pull/119/head
dahall 2020-04-25 15:39:58 -06:00
parent 19706ac13f
commit ee9580be2f
1 changed files with 10 additions and 0 deletions

View File

@ -369,6 +369,11 @@ namespace Vanara.PInvoke
throw exception;
}
/// <summary>Converts a Win32 error to an NTSTATUS.</summary>
/// <param name="x">The Win32 error codex.</param>
/// <returns>The equivalent NTSTATUS value.</returns>
public static NTStatus NTSTATUS_FROM_WIN32(int x) => x <= 0 ? unchecked((uint)x) : (NTStatus)(((x) & 0x0000FFFF) | ((uint)FacilityCode.FACILITY_NTWIN32 << 16) | 0xC0000000);
/// <summary>
/// If the supplied raw NTStatus value represents a failure, throw the associated <see cref="Exception"/> with the optionally
/// supplied message.
@ -425,6 +430,11 @@ namespace Vanara.PInvoke
/// <returns>The result of the conversion.</returns>
public static implicit operator NTStatus(uint value) => new NTStatus(value);
/// <summary>Performs an implicit conversion from <see cref="Win32Error"/> to <see cref="NTStatus"/>.</summary>
/// <param name="value">The value.</param>
/// <returns>The resulting <see cref="NTStatus"/> instance from the conversion.</returns>
public static implicit operator NTStatus(Win32Error value) => NTSTATUS_FROM_WIN32((int)value);
/// <summary>Performs an explicit conversion from <see cref="NTStatus"/> to <see cref="System.Int32"/>.</summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>