// GtkSharp.Boxed.cs - Base class for deriving marshallable structures. // // Author: Mike Kestner // // (c) 2001-2002 Mike Kestner namespace GtkSharp { using System; using System.Runtime.InteropServices; /// /// Boxed Class /// /// /// /// An abstract base class to derive structures and marshal them. /// public abstract class Boxed { IntPtr _raw; // Destructor is required since we are allocating unmanaged // heap resources. ~Boxed () { Marshal.FreeHGlobal (_raw); } /// /// Boxed Constructor /// /// /// /// Dummy constructor needed for subclasses. /// public Boxed() { } /// /// Boxed Constructor /// /// /// /// Wraps a raw boxed type reference. /// public Boxed(IntPtr raw) { Raw = raw; } /// /// Raw Property /// /// /// /// Gets a marshallable IntPtr. /// protected IntPtr Raw { get { if (_raw == IntPtr.Zero) { // FIXME: Ugly hack. _raw = Marshal.AllocHGlobal (128); Marshal.StructureToPtr (this, _raw, true); } return _raw; } set { _raw = value; } } /// /// Handle Property /// /// /// /// Gets a marshallable IntPtr. /// public IntPtr Handle { get { return _raw; } } /// /// GetBoxed Shared Method /// /// /// /// Gets a managed class representing a raw ref. /// public static Boxed GetBoxed (IntPtr raw) { // FIXME: Use the type manager to box the raw ref. return null; } } }