Пример #1
0
        protected virtual void CreateNativeObject(string[] names, GLib.Value[] vals)
        {
            GType gtype = LookupGType();
            bool  is_managed_subclass = GType.IsManaged(gtype);

            GParameter[] parms = new GParameter [is_managed_subclass ? names.Length + 1 : names.Length];
            for (int i = 0; i < names.Length; i++)
            {
                parms [i].name = GLib.Marshaller.StringToPtrGStrdup(names [i]);
                parms [i].val  = vals [i];
            }

            if (is_managed_subclass)
            {
                GCHandle gch = GCHandle.Alloc(this);
                parms[names.Length].name = GLib.Marshaller.StringToPtrGStrdup("gtk-sharp-managed-instance");
                parms[names.Length].val  = new GLib.Value((IntPtr)gch);
                Raw = g_object_newv(gtype.Val, parms.Length, parms);
                gch.Free();
            }
            else
            {
                Raw = g_object_newv(gtype.Val, parms.Length, parms);
            }

            foreach (GParameter p in parms)
            {
                GLib.Marshaller.Free(p.name);
            }
        }
Пример #2
0
        public static N BaseOverride <N>(this AbiStruct class_abi, GType gtype, string fieldname) where N : Delegate
        {
            N unmanaged = null;

            unsafe {
                IntPtr raw_ptr = IntPtr.Zero;
                while (raw_ptr == IntPtr.Zero && GType.IsManaged(gtype))
                {
                    gtype = gtype.GetThresholdType();
                    var abi_ptr = (IntPtr *)(((long)gtype.GetClassPtr()) + (long)class_abi.GetFieldOffset(fieldname));
                    raw_ptr = *abi_ptr;
                }

                if (raw_ptr != IntPtr.Zero)
                {
                    unmanaged = Marshal.GetDelegateForFunctionPointer <N>(raw_ptr);
                }
            }

            return(unmanaged);
        }