I am getting warning when I try to get the value of HRESULT from the com exception and I am suspecting if this is not the correct way to handle a COM exception in C#, please advise the code looks like below.
try
{
...
}
catch (System.Runtime.InteropServices.COMException comex)
{
// Warning 8 Comparison to integral constant is useless; the constant is outside the range of type 'int'
if (comex.ErrorCode == Constants.E_FAIL)
{
}
}
E_FAIL is defined as
public const UInt32 E_FAIL = 0x80004005;
Arguably it would have been more consistent with the Win32 API to define
Exception.HResultasUInt32rather thanInt32akaint.Probably this wasn’t done because UInt32 is not CLS-Compliant.
I would suggest you define your constants as int: