/// <summary>
 /// Map a status to a DOS error code. Takes into account NTWIN32
 /// status codes.
 /// </summary>
 /// <param name="status">The status code.</param>
 /// <returns>The mapped DOS error.</returns>
 public static int MapNtStatusToDosError(NtStatus status)
 {
     if (status.GetFacility() == NtStatusFacility.FACILITY_NTWIN32)
     {
         return(status.GetStatusCode());
     }
     return(NtRtl.RtlNtStatusToDosError(status));
 }
 /// <summary>
 /// Map a status to a DOS error code. Takes into account NTWIN32
 /// status codes.
 /// </summary>
 /// <param name="status">The status code.</param>
 /// <returns>The mapped DOS error.</returns>
 public static Win32Error MapNtStatusToDosError(this NtStatus status)
 {
     if (status.GetFacility() == NtStatusFacility.FACILITY_NTWIN32)
     {
         return((Win32Error)status.GetStatusCode());
     }
     return((Win32Error)NtRtl.RtlNtStatusToDosErrorNoTeb(status));
 }
 internal NtStatusResult(NtStatus status)
 {
     Status       = (uint)status;
     Message      = NtObjectUtils.GetNtStatusMessage(status);
     Win32Error   = NtObjectUtils.MapNtStatusToDosError(status);
     StatusName   = status.ToString();
     Code         = status.GetStatusCode();
     CustomerCode = status.IsCustomerCode();
     Reserved     = status.IsReserved();
     Facility     = status.GetFacility();
     Severity     = status.GetSeverity();
 }
        /// <summary>
        /// Convert an NTSTATUS to a message description.
        /// </summary>
        /// <param name="status">The status to convert.</param>
        /// <returns>The message description, or an empty string if not found.</returns>
        public static string GetNtStatusMessage(NtStatus status)
        {
            SafeLoadLibraryHandle module = SafeLoadLibraryHandle.Null;
            uint message_id = (uint)status;

            if (status.GetFacility() == NtStatusFacility.FACILITY_NTWIN32)
            {
                module     = SafeLoadLibraryHandle.GetModuleHandleNoThrow("kernel32.dll");
                message_id = (uint)status.GetStatusCode();
            }
            else
            {
                module = SafeLoadLibraryHandle.GetModuleHandleNoThrow("ntdll.dll");
            }

            return(Win32Utils.FormatMessage(module, message_id));
        }