fi_handle Structure

FreeImage.NET

fi_handle Structure
Wrapper for a custom handle.

Namespace: FreeImageAPI.IO
Assembly: FreeImageNET (in FreeImageNET.dll) Version: 3.17.0.4 (3.17.0)
Syntax
C#
[SerializableAttribute]
public struct fi_handle : IComparable, IComparable<fi_handle>, 
	IEquatable<fi_handle>, IDisposable

The fi_handle type exposes the following members.

Constructors
  NameDescription
Public methodfi_handle
Initializes a new instance wrapping a managed object.
Top
Properties
  NameDescription
Public propertyIsNull
Gets whether the pointer is a null pointer.
Top
Methods
  NameDescription
Public methodCompareTo(Object)
Compares this instance with a specified Object.
Public methodCompareTo(fi_handle)
Compares this instance with a specified fi_handle object.
Public methodDispose
Releases all resources used by the instance.
Public methodEquals(Object)
Tests whether the specified object is a fi_handle structure and is equivalent to this fi_handle structure.
(Overrides ValueTypeEquals(Object).)
Public methodEquals(fi_handle)
Indicates whether the current object is equal to another object of the same type.
Public methodGetHashCode
Returns a hash code for this fi_handle structure.
(Overrides ValueTypeGetHashCode.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Converts the numeric value of the fi_handle object to its equivalent string representation.
(Overrides ValueTypeToString.)
Top
Operators
  NameDescription
Public operatorStatic memberEquality
Tests whether two specified fi_handle structures are equivalent.
Public operatorStatic memberInequality
Tests whether two specified fi_handle structures are different.
Top
Fields
  NameDescription
Public fieldhandle
The handle to wrap.
Top
Remarks
The fi_handle of FreeImage in C++ is a simple pointer, but in .NET it's not that simple. This wrapper uses fi_handle in two different ways. We implement a new plugin and FreeImage gives us a handle (pointer) that we can simply pass through to the given functions in a 'FreeImageIO' structure. But when we want to use LoadFromhandle or SaveToHandle we need a fi_handle (that we receive again in our own functions). This handle is for example a stream (see LoadFromStream / SaveToStream) that we want to work with. To know which stream a read/write is meant for we could use a hash value that the wrapper itself handles or we can go the unmanaged way of using a handle. Therefor we use a GCHandle to receive a unique pointer that we can convert back into a .NET object. When the fi_handle instance is no longer needed the instance must be disposed by the creater manually! It is recommended to use the using statement to be sure the instance is always disposed:
using (fi_handle handle = new fi_handle(object))
{
    callSomeFunctions(handle);
}
What does that mean? If we get a fi_handle from unmanaged code we get a pointer to unmanaged memory that we do not have to care about, and just pass ist back to FreeImage. If we have to create a handle our own we use the standard constructur that fills the IntPtr with an pointer that represents the given object. With calling GetObject the IntPtr is used to retrieve the original object we passed through the constructor. This way we can implement a fi_handle that works with managed an unmanaged code.
See Also