Wrapper for a custom handle.

Namespace:  FreeImageAPI.IO
Assembly:  FreeImageNET (in FreeImageNET.dll)


public struct fi_handle : IComparable, IComparable<fi_handle>, 
	IEquatable<fi_handle>, IDisposable
Visual Basic (Declaration)
<SerializableAttribute> _
Public Structure fi_handle _
	Implements IComparable, IComparable(Of fi_handle),  _
	IEquatable(Of fi_handle), IDisposable
Visual C++
public value class fi_handle : IComparable, 
	IComparable<fi_handle>, IEquatable<fi_handle>, IDisposable


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))
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.

Version Information


Supported in: 3.11.0, 3.12.0, 3.13.0, 3.13.1

See Also