using Microsoft.Win32.SafeHandles;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// Signals that a structure or class holds a handle to a synchronization object.
public interface IGraphicsObjectHandle : IUserHandle { }
/// Signals that a structure or class holds a HANDLE.
public interface IHandle
{
/// Returns the value of the handle field.
/// An IntPtr representing the value of the handle field.
IntPtr DangerousGetHandle();
}
/// Signals that a structure or class holds a handle to a synchronization object.
public interface IKernelHandle : IHandle { }
/// Signals that a structure or class holds a pointer to a security object.
public interface ISecurityObject : IHandle { }
/// Signals that a structure or class holds a handle to a synchronization object.
public interface IShellHandle : IHandle { }
/// Signals that a structure or class holds a handle to a synchronization object.
public interface ISyncHandle : IKernelHandle { }
/// Signals that a structure or class holds a handle to a synchronization object.
public interface IUserHandle : IHandle { }
/// Provides a handle to an accelerator table.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HACCEL : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HACCEL(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HACCEL NULL => new HACCEL(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HACCEL h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HACCEL(IntPtr h) => new HACCEL(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HACCEL h1, HACCEL h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HACCEL h1, HACCEL h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HACCEL h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a generic handle.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HANDLE : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HANDLE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HANDLE NULL => new HANDLE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HANDLE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HANDLE(IntPtr h) => new HANDLE(h);
/// Performs an implicit conversion from to .
/// The h.
/// The result of the conversion.
public static implicit operator HANDLE(SafeHANDLE h) => new HANDLE(h.DangerousGetHandle());
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HANDLE h1, HANDLE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HANDLE h1, HANDLE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HANDLE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a bitmap.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HBITMAP : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HBITMAP(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HBITMAP NULL => new HBITMAP(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HBITMAP h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HBITMAP(IntPtr h) => new HBITMAP(h);
/// Performs an implicit conversion from to .
/// The pointer to a GDI handle.
/// The result of the conversion.
public static implicit operator HBITMAP(HGDIOBJ h) => new HBITMAP((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HBITMAP h1, HBITMAP h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HBITMAP h1, HBITMAP h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HBITMAP h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a drawing brush.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HBRUSH : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HBRUSH(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HBRUSH NULL => new HBRUSH(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HBRUSH h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HBRUSH(IntPtr h) => new HBRUSH(h);
/// Performs an implicit conversion from to .
/// The pointer to a GDI handle.
/// The result of the conversion.
public static implicit operator HBRUSH(HGDIOBJ h) => new HBRUSH((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HBRUSH h1, HBRUSH h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HBRUSH h1, HBRUSH h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HBRUSH h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a color space.
[StructLayout(LayoutKind.Sequential)]
public struct HCOLORSPACE : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HCOLORSPACE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HCOLORSPACE NULL => new HCOLORSPACE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HCOLORSPACE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HCOLORSPACE(IntPtr h) => new HCOLORSPACE(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HCOLORSPACE h1, HCOLORSPACE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HCOLORSPACE h1, HCOLORSPACE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HCOLORSPACE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows cursor.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HCURSOR : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HCURSOR(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HCURSOR NULL => new HCURSOR(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HCURSOR h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HCURSOR(IntPtr h) => new HCURSOR(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HCURSOR h1, HCURSOR h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HCURSOR h1, HCURSOR h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HCURSOR h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a graphic device context.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HDC : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HDC(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HDC NULL => new HDC(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HDC h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HDC(IntPtr h) => new HDC(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HDC h1, HDC h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HDC h1, HDC h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HDC h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a desktop.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HDESK : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HDESK(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HDESK NULL => new HDESK(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HDESK h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HDESK(IntPtr h) => new HDESK(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HDESK h1, HDESK h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HDESK h1, HDESK h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HDESK h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a DPA.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HDPA : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HDPA(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HDPA NULL => new HDPA(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HDPA h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HDPA(IntPtr h) => new HDPA(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HDPA h1, HDPA h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HDPA h1, HDPA h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HDPA h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows drop operation.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HDROP : IShellHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HDROP(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HDROP NULL => new HDROP(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HDROP h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HDROP(IntPtr h) => new HDROP(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HDROP h1, HDROP h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HDROP h1, HDROP h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HDROP h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a DSA.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HDSA : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HDSA(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HDSA NULL => new HDSA(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HDSA h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HDSA(IntPtr h) => new HDSA(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HDSA h1, HDSA h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HDSA h1, HDSA h2) => h1.Equals(h2);
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
/// true if the specified is equal to this instance; otherwise, false.
public override bool Equals(object obj) => obj is HDSA h ? handle == h.handle : false;
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a deferred windows position.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HDWP : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HDWP(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HDWP NULL => new HDWP(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HDWP h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HDWP(IntPtr h) => new HDWP(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HDWP h1, HDWP h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HDWP h1, HDWP h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HDWP h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to an enhanced metafile.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HENHMETAFILE : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HENHMETAFILE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HENHMETAFILE NULL => new HENHMETAFILE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HENHMETAFILE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HENHMETAFILE(IntPtr h) => new HENHMETAFILE(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HENHMETAFILE h1, HENHMETAFILE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HENHMETAFILE h1, HENHMETAFILE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HENHMETAFILE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a file.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HFILE : IKernelHandle
{
/// Represents an invalid handle.
public static readonly HFILE INVALID_HANDLE_VALUE = new IntPtr(-1);
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HFILE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HFILE NULL => new HFILE(IntPtr.Zero);
/// Gets a value indicating whether this instance is an invalid handle (INVALID_HANDLE_VALUE).
public bool IsInvalid => handle == INVALID_HANDLE_VALUE;
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HFILE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HFILE(IntPtr h) => new HFILE(h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HFILE(SafeFileHandle h) => new HFILE(h?.DangerousGetHandle() ?? IntPtr.Zero);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HFILE h1, HFILE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HFILE h1, HFILE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HFILE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a font.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HFONT : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HFONT(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HFONT NULL => new HFONT(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HFONT h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HFONT(IntPtr h) => new HFONT(h);
/// Performs an implicit conversion from to .
/// The pointer to a GDI handle.
/// The result of the conversion.
public static implicit operator HFONT(HGDIOBJ h) => new HFONT((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HFONT h1, HFONT h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HFONT h1, HFONT h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HFONT h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a graphic device object.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HGDIOBJ : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HGDIOBJ(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HGDIOBJ NULL => new HGDIOBJ(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HGDIOBJ h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(IntPtr h) => new HGDIOBJ(h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HBITMAP h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HBRUSH h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HCOLORSPACE h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HDC h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HFONT h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HMETAFILE h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HENHMETAFILE h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HPALETTE h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HPEN h) => new HGDIOBJ((IntPtr)h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HGDIOBJ(HRGN h) => new HGDIOBJ((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HGDIOBJ h1, HGDIOBJ h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HGDIOBJ h1, HGDIOBJ h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HGDIOBJ h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows icon.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HICON : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HICON(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HICON NULL => new HICON(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HICON h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HICON(IntPtr h) => new HICON(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HICON h1, HICON h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HICON h1, HICON h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HICON h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows image list.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HIMAGELIST : IShellHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HIMAGELIST(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HIMAGELIST NULL => new HIMAGELIST(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HIMAGELIST h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HIMAGELIST(IntPtr h) => new HIMAGELIST(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HIMAGELIST h1, HIMAGELIST h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HIMAGELIST h1, HIMAGELIST h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HIMAGELIST h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a module or library instance.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HINSTANCE : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HINSTANCE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HINSTANCE NULL => new HINSTANCE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HINSTANCE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HINSTANCE(IntPtr h) => new HINSTANCE(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HINSTANCE h1, HINSTANCE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HINSTANCE h1, HINSTANCE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HINSTANCE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows registry key.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HKEY : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HKEY(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HKEY NULL => new HKEY(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
///
/// Registry entries subordinate to this key define types (or classes) of documents and the properties associated with those types.
/// Shell and COM applications use the information stored under this key.
///
public static readonly HKEY HKEY_CLASSES_ROOT = new HKEY(new IntPtr(unchecked((int)0x80000000)));
///
/// Contains information about the current hardware profile of the local computer system. The information under HKEY_CURRENT_CONFIG
/// describes only the differences between the current hardware configuration and the standard configuration. Information about the
/// standard hardware configuration is stored under the Software and System keys of HKEY_LOCAL_MACHINE.
///
public static readonly HKEY HKEY_CURRENT_CONFIG = new HKEY(new IntPtr(unchecked((int)0x80000005)));
///
/// Registry entries subordinate to this key define the preferences of the current user. These preferences include the settings of
/// environment variables, data about program groups, colors, printers, network connections, and application preferences. This key
/// makes it easier to establish the current user's settings; the key maps to the current user's branch in HKEY_USERS. In
/// HKEY_CURRENT_USER, software vendors store the current user-specific preferences to be used within their applications. Microsoft,
/// for example, creates the HKEY_CURRENT_USER\Software\Microsoft key for its applications to use, with each application creating its
/// own subkey under the Microsoft key.
///
public static readonly HKEY HKEY_CURRENT_USER = new HKEY(new IntPtr(unchecked((int)0x80000001)));
///
public static readonly HKEY HKEY_DYN_DATA = new HKEY(new IntPtr(unchecked((int)0x80000006)));
///
/// Registry entries subordinate to this key define the physical state of the computer, including data about the bus type, system
/// memory, and installed hardware and software. It contains subkeys that hold current configuration data, including Plug and Play
/// information (the Enum branch, which includes a complete list of all hardware that has ever been on the system), network logon
/// preferences, network security information, software-related information (such as server names and the location of the server),
/// and other system information.
///
public static readonly HKEY HKEY_LOCAL_MACHINE = new HKEY(new IntPtr(unchecked((int)0x80000002)));
///
/// Registry entries subordinate to this key allow you to access performance data. The data is not actually stored in the registry;
/// the registry functions cause the system to collect the data from its source.
///
public static readonly HKEY HKEY_PERFORMANCE_DATA = new HKEY(new IntPtr(unchecked((int)0x80000004)));
///
/// Registry entries subordinate to this key define the default user configuration for new users on the local computer and the user
/// configuration for the current user.
///
public static readonly HKEY HKEY_USERS = new HKEY(new IntPtr(unchecked((int)0x80000003)));
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HKEY h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HKEY(IntPtr h) => new HKEY(h);
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HKEY(SafeRegistryHandle h) => new HKEY(h.DangerousGetHandle());
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HKEY h1, HKEY h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HKEY h1, HKEY h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HKEY h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a menu.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HMENU : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HMENU(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HMENU NULL => new HMENU(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HMENU h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HMENU(IntPtr h) => new HMENU(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HMENU h1, HMENU h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HMENU h1, HMENU h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HMENU h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a metafile.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HMETAFILE : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HMETAFILE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HMETAFILE NULL => new HMETAFILE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HMETAFILE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HMETAFILE(IntPtr h) => new HMETAFILE(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HMETAFILE h1, HMETAFILE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HMETAFILE h1, HMETAFILE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HMETAFILE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a monitor.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HMONITOR : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HMONITOR(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HMONITOR NULL => new HMONITOR(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HMONITOR h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HMONITOR(IntPtr h) => new HMONITOR(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HMONITOR h1, HMONITOR h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HMONITOR h1, HMONITOR h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HMONITOR h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a palette.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HPALETTE : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HPALETTE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HPALETTE NULL => new HPALETTE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HPALETTE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HPALETTE(IntPtr h) => new HPALETTE(h);
/// Performs an implicit conversion from to .
/// The pointer to a GDI handle.
/// The result of the conversion.
public static implicit operator HPALETTE(HGDIOBJ h) => new HPALETTE((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HPALETTE h1, HPALETTE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HPALETTE h1, HPALETTE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HPALETTE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a drawing pen.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HPEN : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HPEN(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HPEN NULL => new HPEN(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HPEN h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HPEN(IntPtr h) => new HPEN(h);
/// Performs an implicit conversion from to .
/// The pointer to a GDI handle.
/// The result of the conversion.
public static implicit operator HPEN(HGDIOBJ h) => new HPEN((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HPEN h1, HPEN h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HPEN h1, HPEN h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HPEN h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a process.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HPROCESS : ISyncHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HPROCESS(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HPROCESS NULL => new HPROCESS(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HPROCESS h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HPROCESS(IntPtr h) => new HPROCESS(h);
/// Performs an implicit conversion from to .
/// The Process instance.
/// The result of the conversion.
public static implicit operator HPROCESS(Process p) => new HPROCESS(p.Handle);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HPROCESS h1, HPROCESS h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HPROCESS h1, HPROCESS h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HPROCESS h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows property sheet.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HPROPSHEET : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HPROPSHEET(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HPROPSHEET NULL => new HPROPSHEET(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HPROPSHEET h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HPROPSHEET(IntPtr h) => new HPROPSHEET(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HPROPSHEET h1, HPROPSHEET h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HPROPSHEET h1, HPROPSHEET h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HPROPSHEET h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a property sheet page.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HPROPSHEETPAGE : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HPROPSHEETPAGE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HPROPSHEETPAGE NULL => new HPROPSHEETPAGE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HPROPSHEETPAGE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HPROPSHEETPAGE(IntPtr h) => new HPROPSHEETPAGE(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HPROPSHEETPAGE h1, HPROPSHEETPAGE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HPROPSHEETPAGE h1, HPROPSHEETPAGE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HPROPSHEETPAGE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a drawing region.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HRGN : IGraphicsObjectHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HRGN(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HRGN NULL => new HRGN(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HRGN h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HRGN(IntPtr h) => new HRGN(h);
/// Performs an implicit conversion from to .
/// The pointer to a GDI handle.
/// The result of the conversion.
public static implicit operator HRGN(HGDIOBJ h) => new HRGN((IntPtr)h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HRGN h1, HRGN h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HRGN h1, HRGN h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HRGN h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a file mapping object.
[StructLayout(LayoutKind.Sequential)]
public struct HSECTION : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HSECTION(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HSECTION NULL => new HSECTION(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HSECTION h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HSECTION(IntPtr h) => new HSECTION(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HSECTION h1, HSECTION h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HSECTION h1, HSECTION h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HSECTION h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a blocking task.
[StructLayout(LayoutKind.Sequential)]
public struct HTASK : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HTASK(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HTASK NULL => new HTASK(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HTASK h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HTASK(IntPtr h) => new HTASK(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HTASK h1, HTASK h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HTASK h1, HTASK h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HTASK h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows theme.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HTHEME : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HTHEME(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HTHEME NULL => new HTHEME(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HTHEME h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HTHEME(IntPtr h) => new HTHEME(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HTHEME h1, HTHEME h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HTHEME h1, HTHEME h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HTHEME h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a thread.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HTHREAD : ISyncHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HTHREAD(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HTHREAD NULL => new HTHREAD(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HTHREAD h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HTHREAD(IntPtr h) => new HTHREAD(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HTHREAD h1, HTHREAD h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HTHREAD h1, HTHREAD h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HTHREAD h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a Windows thumbnail.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HTHUMBNAIL : IShellHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HTHUMBNAIL(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HTHUMBNAIL NULL => new HTHUMBNAIL(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HTHUMBNAIL h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HTHUMBNAIL(IntPtr h) => new HTHUMBNAIL(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HTHUMBNAIL h1, HTHUMBNAIL h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HTHUMBNAIL h1, HTHUMBNAIL h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HTHUMBNAIL h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to an access token .
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HTOKEN : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HTOKEN(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HTOKEN NULL => new HTOKEN(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HTOKEN h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HTOKEN(IntPtr h) => new HTOKEN(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HTOKEN h1, HTOKEN h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HTOKEN h1, HTOKEN h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HTOKEN h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a windows station.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HWINSTA : IKernelHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HWINSTA(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HWINSTA NULL => new HWINSTA(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HWINSTA h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HWINSTA(IntPtr h) => new HWINSTA(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HWINSTA h1, HWINSTA h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HWINSTA h1, HWINSTA h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HWINSTA h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a window or dialog.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct HWND : IUserHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HWND(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HWND NULL => new HWND(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HWND h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HWND(IntPtr h) => new HWND(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HWND h1, HWND h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HWND h1, HWND h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HWND h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a pointer to an access control entry.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct PACE : ISecurityObject
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public PACE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static PACE NULL => new PACE(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(PACE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator PACE(IntPtr h) => new PACE(h);
///
public override bool Equals(object obj) => obj is PACE h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a pointer to an access control list.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct PACL : ISecurityObject
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public PACL(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static PACL NULL => new PACL(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(PACL h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator PACL(IntPtr h) => new PACL(h);
///
public override bool Equals(object obj) => obj is PACL h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a pointer to a security descriptor.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct PSECURITY_DESCRIPTOR : ISecurityObject
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public PSECURITY_DESCRIPTOR(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static PSECURITY_DESCRIPTOR NULL => new PSECURITY_DESCRIPTOR(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(PSECURITY_DESCRIPTOR h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator PSECURITY_DESCRIPTOR(IntPtr h) => new PSECURITY_DESCRIPTOR(h);
///
public override bool Equals(object obj) => obj is PSECURITY_DESCRIPTOR h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a pointer to a security identifier.
[StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")]
public struct PSID : ISecurityObject
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public PSID(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static PSID NULL => new PSID(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(PSID h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator PSID(IntPtr h) => new PSID(h);
///
public override bool Equals(object obj) => obj is PSID h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Base class for all native handles.
///
///
///
[DebuggerDisplay("{handle}")]
public abstract class SafeHANDLE : SafeHandleZeroOrMinusOneIsInvalid, IEquatable, IHandle
{
/// Initializes a new instance of the class.
public SafeHANDLE() : base(true)
{
}
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
protected SafeHANDLE(IntPtr preexistingHandle, bool ownsHandle = true) : base(ownsHandle) => SetHandle(preexistingHandle);
/// Gets a value indicating whether this instance is null.
/// true if this instance is null; otherwise, false.
public bool IsNull => handle == IntPtr.Zero;
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(SafeHANDLE h1, SafeHANDLE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(SafeHANDLE h1, SafeHANDLE h2) => h1?.Equals(h2) ?? h2 is null;
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
/// true if the specified is equal to this instance; otherwise, false.
public bool Equals(SafeHANDLE other)
{
if (other is null)
return false;
if (ReferenceEquals(this, other))
return true;
return handle == other.handle && IsClosed == other.IsClosed;
}
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
/// true if the specified is equal to this instance; otherwise, false.
public override bool Equals(object obj)
{
switch (obj)
{
case IHandle ih:
return handle.Equals(ih.DangerousGetHandle());
case SafeHandle sh:
return handle.Equals(sh.DangerousGetHandle());
case IntPtr p:
return handle.Equals(p);
default:
return base.Equals(obj);
}
}
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode() => base.GetHashCode();
///
/// Internal method that actually releases the handle. This is called by for valid handles and afterwards
/// zeros the handle.
///
/// true to indicate successful release of the handle; false otherwise.
protected abstract bool InternalReleaseHandle();
///
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
protected override bool ReleaseHandle()
{
if (IsInvalid) return true;
if (!InternalReleaseHandle()) return false;
handle = IntPtr.Zero;
return true;
}
}
}