See Also: SafeHandle Members
System.Object
System.Runtime.ConstrainedExecution.CriticalFinalizerObject
System.Runtime.InteropServices.SafeHandle
In the past, developers used the IntPtr as an opaque value that typically mapped to operating system handles. There were two major problems with this: there was no type safety and on sandboxed setups it was possible to create an attack depending on handle reuse while some code executed in the underlying operating system.
SafeHandles are derived from this class and have to provide the proper mechanism for disposing a handle (file handles would close th underling operating system descriptor for example) and so so by overwritting the ReleaseHandle method.
SafeHandles and its derived types are passed in Platform Invocation calls (DllImports) and the runtime will transform the actual type-safe SafeHandle into the opaque handle (the runtime will call DangerousGetHandle () transparently).
In P/Invoke, SafeHandles can be passed as parameters and as reference parameters. They can be returned from methods and passed in structures. There is one limitation though: SafeHandles contained in ref structures will not have their values modified on the structure (In .NET or in Mono).
For an up-to-date description of all the features of SafeHandles in Mono see the tp://www.mono-project.com/SafeHandles page.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0
Since: