HRESULTs are the common way for Microsoft technologies like COM and Win32 to return either an error code or messages that mean a specific type of success.  They are usually returned as the result of a function.  They have various pieces of information encoded in their bits, such as the OS facility that erred, the error code, etc.  Since I am not someone who can intuitively decode bits in my head, I wanted to have a class to encapsulate the logic so I can call it whenever I need to know what an HRESULT really says.References:https://msdn.microsoft.com/en-us/library/cc231198.aspxhttps://blogs.msdn.microsoft.com/heaths/2005/07/21/deciphering-an-hresult/https://blogs.msdn.microsoft.com/eldar/2007/04/03/a-lot-of-hresult-codes/Public Structure HResult    Implements IEquatable(Of HResult), IEquatable(Of Integer)Public Enum SeverityCode    Success = 0           'STATUS_SEVERITY_SUCCESS    Informational = &H1   'STATUS_SEVERITY_INFORMATIONAL    Warning = &H2         'STATUS_SEVERITY_WARNING    [Error] = &H3         'STATUS_SEVERITY_ERROREnd EnumPrivate Enum BitMasks As Integer    IsError = &H80000000    SeverityShifted = &H3    Customer = &H20000000    ISNTError = &H10000000    Facility = &HFFF0000    Code = &HFFFFEnd EnumPublic Sub New(hresult As Integer)    _Hresult = hresultEnd SubPublic ReadOnly Property Hresult As IntegerPublic ReadOnly Property ErrorCode As Integer    Get        Return Hresult And BitMasks.Code    End GetEnd PropertyPublic ReadOnly Property IsError As Boolean    Get        Return (Hresult And BitMasks.IsError) <> 0    End GetEnd PropertyPublic ReadOnly Property IsNTError As Boolean    Get        Return (Hresult And BitMasks.ISNTError) <> 0    End GetEnd PropertyPublic ReadOnly Property Severity As SeverityCode    Get        Return DirectCast((Hresult >> 30) And BitMasks.SeverityShifted, SeverityCode)    End GetEnd PropertyPublic ReadOnly Property MicrosoftDefined As Boolean    Get        Return (Hresult And BitMasks.Customer) = 0    End GetEnd PropertyPublic ReadOnly Property Facility As Integer    Get        Return (Hresult And BitMasks.Facility) >> 16    End GetEnd PropertyPublic Shared Widening Operator CType(v As Integer) As HResult    Return v.AsHResultEnd OperatorPublic Shared Widening Operator CType(v As HResult) As Integer    Return v.HresultEnd Operator#Region IEquatablePublic Overloads Function Equals(other As HResult) As Boolean Implements IEquatable(Of HResult).Equals    Return (Hresult = other.Hresult)End FunctionPublic Overloads Function Equals(other As Integer) As Boolean Implements IEquatable(Of Integer).Equals    Return (Hresult = other)End FunctionPublic Overrides Function Equals(obj As Object) As Boolean    If obj Is Nothing Then Return False    If TypeOf obj Is HResult Then Return Equals(DirectCast(obj, HResult))    If TypeOf obj Is Integer Then Return Equals(DirectCast(obj, Integer))    Return FalseEnd FunctionPublic Overrides Function GetHashCode() As Integer    Return Hresult.GetHashCodeEnd FunctionPublic Shared Operator =(itm1 As HResult, itm2 As HResult) As Boolean    If IsNothing(itm1) And IsNothing(itm2) Then Return True    If IsNothing(itm1) Then        Return False    Else        Return itm1.Equals(itm2)    End IfEnd OperatorPublic Shared Operator <>(itm1 As HResult, itm2 As HResult) As Boolean    Return Not (itm1 = itm2)End Operator#End RegionEnd StructurePublic Module HResultExtensions<Runtime.CompilerServices.Extension()>Public Function AsHResult(hresult As Integer) As HResult    Return New HResult(hresult)End Function<Runtime.CompilerServices.Extension()>Public Function AsHResult(hresult As [Enum]) As HResult    If [Enum].GetUnderlyingType(hresult.GetType) <> GetType(Integer) Then Throw New ArgumentException(Argument provided does not represent a 32 bit integer.)    Return New HResult(Convert.ToInt32(hresult))End FunctionEnd ModuleAnd also the tests that I used to check for correctness:<TestClass>Public Class TestHResult<TestMethod()> Public Sub Test_ErrorCode_NullPointer()    Dim ex = New ArgumentNullException    Dim HR = ex.HResult.AsHResult    Assert.IsTrue(HR.ErrorCode = 16387 AndAlso                  HR.IsError = True AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Warning AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_NULL                  )End Sub<TestMethod()> Public Sub Test_ErrorCode_Argument()    Dim ex = New ArgumentException    Dim HR = ex.HResult.AsHResult    Assert.IsTrue(HR.ErrorCode = 87 AndAlso                  HR.IsError = True AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Warning AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_WIN32                  )End Sub<TestMethod()> Public Sub Test_ErrorCode_FileNotFound()    Dim ex = New System.IO.FileNotFoundException    Dim HR = ex.HResult.AsHResult    Assert.IsTrue(HR.ErrorCode = 2 AndAlso                  HR.IsError = True AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Warning AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_WIN32                  )End Sub<TestMethod()> Public Sub Test_ErrorCode_Overflow()    Dim ex = New OverflowException    Dim HR = ex.HResult.AsHResult    Assert.IsTrue(HR.ErrorCode = 5398 AndAlso                  HR.IsError = True AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Warning AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_URT                  )End Sub<TestMethod()> Public Sub Test_ErrorCode_Auditing()    Dim HR = KnownHResults.ERROR_AUDITING_DISABLED.AsHResult    Assert.IsTrue(HR.ErrorCode = 1 AndAlso                  HR.IsError = True AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Error AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_SSPI                  )End Sub<TestMethod()> Public Sub Test_Informational()    Dim HR = KnownHResults.TEST_INFORMATIONAL.AsHResult    Assert.IsTrue(HR.ErrorCode = 0 AndAlso                  HR.IsError = False AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Informational AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_NULL                  )End Sub<TestMethod()> Public Sub Test_Customer()    Dim HR = KnownHResults.TEST_CUSTOMER.AsHResult    Assert.IsTrue(HR.ErrorCode = 0 AndAlso                  HR.IsError = True AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Warning AndAlso                  HR.MicrosoftDefined = False AndAlso                  HR.Facility = KnownFacilities.FACILITY_NULL                  )End Sub<TestMethod()> Public Sub Test_Success()    Dim HR = KnownHResults.S_OK.AsHResult    Assert.IsTrue(HR.ErrorCode = 0 AndAlso                  HR.IsError = False AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Success AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_NULL                  )End Sub<TestMethod()> Public Sub Test_False()    Dim HR = KnownHResults.S_FALSE.AsHResult    Assert.IsTrue(HR.ErrorCode = 1 AndAlso                  HR.IsError = False AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Success AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_NULL                  )End Sub<TestMethod()> Public Sub Test_OLE_First()    Dim HR = KnownHResults.OLE_S_FIRST.AsHResult    Assert.IsTrue(HR.ErrorCode = 0 AndAlso                  HR.IsError = False AndAlso                  HR.IsNTError = False AndAlso                  HR.Severity = HResult.SeverityCode.Success AndAlso                  HR.MicrosoftDefined = True AndAlso                  HR.Facility = KnownFacilities.FACILITY_ITF                  )End SubEnum KnownHResults As Integer    S_OK = 0                                '&H00000000    S_FALSE = 1                             '&H00000001    OLE_S_FIRST = 262144                    '&H00040000    COR_E_NULLREFERENCE = -2147467261       '&H80004003    E_INVALIDARG = -2147024809              '&H80070057     ERROR_AUDITING_DISABLED = -1073151999   '&HC0090001    TEST_INFORMATIONAL = 1073741824         '&H40000000    TEST_CUSTOMER = -1610612736             '&HA0000000End EnumEnum KnownFacilities As Integer    FACILITY_NULL = 0    FACILITY_ITF = 4    FACILITY_WIN32 = 7    FACILITY_SSPI = 9    FACILITY_URT = 19End EnumEnd Class
A class (actually a structure) to help decode an HRESULT
vb.net;com