# HRESULT

```csharp
[DebuggerDisplay("{Value}")]
public readonly struct HRESULT : IEquatable<HRESULT>
{
    public readonly int Value;

    public HRESULT(int value) => Value = value;

    public static implicit operator int(HRESULT value) => value.Value;

    public static explicit operator HRESULT(int value) => new(value);

    public static bool operator ==(HRESULT left, HRESULT right) => left.Value == right.Value;

    public static bool operator !=(HRESULT left, HRESULT right) => !(left == right);

    public bool Equals(HRESULT other) => Value == other.Value;

    public override bool Equals(object obj) => obj is HRESULT other && Equals(other);

    public override int GetHashCode() => Value.GetHashCode();

    public override string ToString() => string.Format(System.Globalization.CultureInfo.InvariantCulture, "0x{0:X8}", Value);

    public static implicit operator uint(HRESULT value) => (uint)value.Value;

    public static explicit operator HRESULT(uint value) => new((int)value);

    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public bool Succeeded => Value >= 0;

    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public bool Failed => Value < 0;

    public HRESULT ThrowOnFailure(IntPtr errorInfo = default)
    {
        Marshal.ThrowExceptionForHR(Value, errorInfo);
        return this;
    }

    public string ToString(string format, IFormatProvider formatProvider) => ((uint)Value).ToString(format, formatProvider);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pinvoke.dev/foundation/hresult.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
