I am know NTSTATUS that i will get in case of specific error, but i got hresult, not ntstatus from pinvoke. So how to convert specific NTSTATUS value to the Hresult.
I tried with no success:
class Program
{
private const int FacilityNtBit = 0x10000000;
//#define STATUS_DUPLICATE_OBJECTID ((NTSTATUS)0xC000022AL)
private const int STATUS_DUPLICATE_OBJECTID = unchecked((int) (0xC000022A));
// HResult that is returned for the STATUS_DUPLICATE_OBJECTID
private const int CorrectHrStatusDuplicateObjectid = -2147019886;
static void Main(string[] args)
{
int res = HRESULT_FROM_NT(STATUS_DUPLICATE_OBJECTID);
Debug.Assert(res == CorrectHrStatusDuplicateObjectid, "Must be the same");
}
private static int HRESULT_FROM_NT(int ntStatus)
{
//#define HRESULT_FROM_NT(x) ((HRESULT) ((x) | FACILITY_NT_BIT))
return ntStatus | FacilityNtBit;
}
}