public static void Subscribe(IDisposable instance, Type interfaceCOM) { IntPtr pUnk = Marshal.GetComInterfaceForObject(instance, interfaceCOM); IntPtr vtable = Marshal.ReadIntPtr(pUnk); COMDisposable item = (COMDisposable)ITEMS[vtable]; if (item == null) { //gets the the Release function IntPtr releaseOriPtr = Marshal.ReadIntPtr(vtable, RELEASE_PTR_OFFSET); ReleaseDelegate releaseOri = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer( releaseOriPtr, typeof(ReleaseDelegate)); //saves the original function and reference count item = new COMDisposable(); item.ReleaseOri = releaseOri; item.RefCountStart = releaseOri(pUnk); ITEMS.Add(vtable, item); //overrides the Release function Marshal.WriteIntPtr(vtable, RELEASE_PTR_OFFSET, ReleaseNewPtr); } else { item.ReleaseOri(pUnk); } }
public COMCallableIUnknown() { _handle = GCHandle.Alloc(this); IUnknownVTable * vtable = (IUnknownVTable *)Marshal.AllocHGlobal(sizeof(IUnknownVTable)).ToPointer(); QueryInterfaceDelegate qi = new QueryInterfaceDelegate(QueryInterfaceImpl); vtable->QueryInterface = Marshal.GetFunctionPointerForDelegate(qi); _delegates.Add(qi); AddRefDelegate addRef = new AddRefDelegate(AddRefImpl); vtable->AddRef = Marshal.GetFunctionPointerForDelegate(addRef); _delegates.Add(addRef); ReleaseDelegate release = new ReleaseDelegate(ReleaseImpl); vtable->Release = Marshal.GetFunctionPointerForDelegate(release); _delegates.Add(release); IUnknownObject = Marshal.AllocHGlobal(IntPtr.Size); *(void **)IUnknownObject = vtable; _interfaces.Add(IUnknownGuid, IUnknownObject); }
public static void CreditCCPayment <TNode>(TNode doc, string aPCRefTranNbr, PXSelectBase <CCProcTran> ccProcTran, bool doRelease, ReleaseDelegate CustomPreReleaseDelegate) where TNode : ARRegister, IBqlTable, ICCPayment, new() { ReleaseDelegate combinedReleaseDelegate = doRelease ? CustomPreReleaseDelegate + ReleaseARDocument : CustomPreReleaseDelegate; CreditCCPayment <TNode>(doc, aPCRefTranNbr, ccProcTran, combinedReleaseDelegate, null); }
public static void VoidCCPayment <TNode>(TNode doc, PXSelectBase <CCProcTran> ccProcTran, bool doRelease, ReleaseDelegate CustomPreReleaseDelegate) where TNode : ARRegister, ICCPayment, new() { ReleaseDelegate combinedReleaseDelegate = doRelease ? CustomPreReleaseDelegate + ReleaseARDocument : CustomPreReleaseDelegate; VoidCCPayment <TNode>(doc, ccProcTran, combinedReleaseDelegate, null); }
public void SetVerticalFontExtentsDelegate(FontExtentsDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_font_v_extents_func(Handle, DelegateProxies.FontExtentsProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetGlyphFromNameDelegate(GlyphFromNameDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_from_name_func(Handle, DelegateProxies.GlyphFromNameProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetGlyphContourPointDelegate(GlyphContourPointDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_contour_point_func(Handle, DelegateProxies.GlyphContourPointProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetVerticalGlyphOriginDelegate(GlyphOriginDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_v_origin_func(Handle, DelegateProxies.GlyphOriginProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetHorizontalGlyphAdvanceDelegate(GlyphAdvanceDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_h_advance_func(Handle, DelegateProxies.GlyphAdvanceProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetNominalGlyphsDelegate(NominalGlyphsDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_nominal_glyphs_func(Handle, DelegateProxies.NominalGlyphsProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetVariationGlyphDelegate(VariationGlyphDelegate del, ReleaseDelegate destroy) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_variation_glyph_func(Handle, DelegateProxies.VariationGlyphProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetComposeDelegate(ComposeDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, new UserDataDelegate(() => this), destroy); HarfBuzzApi.hb_unicode_funcs_set_compose_func(Handle, DelegateProxies.ComposeProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetScriptDelegate(ScriptDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMultiUserData(del, destroy, this); HarfBuzzApi.hb_unicode_funcs_set_script_func( Handle, DelegateProxies.ScriptProxy, (void *)ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetFontFunctions(FontFunctions fontFunctions, object fontData, ReleaseDelegate destroy) { _ = fontFunctions ?? throw new ArgumentNullException(nameof(fontFunctions)); var container = new FontUserData(this, fontData); var ctx = DelegateProxies.CreateMultiUserData(destroy, container); HarfBuzzApi.hb_font_set_funcs(Handle, fontFunctions.Handle, (void *)ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetGlyphExtentsDelegate(GlyphExtentsDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_extents_func( Handle, DelegateProxies.GlyphExtentsProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetHorizontalGlyphKerningDelegate(GlyphKerningDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_h_kerning_func( Handle, DelegateProxies.GlyphKerningProxy, (void *)ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetDecomposeDelegate(DecomposeDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMultiUserData(del, destroy, this); HarfBuzzApi.hb_unicode_funcs_set_decompose_func( Handle, DelegateProxies.DecomposeProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetVerticalGlyphAdvancesDelegate(GlyphAdvancesDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMulti(del, destroy); HarfBuzzApi.hb_font_funcs_set_glyph_v_advances_func( Handle, DelegateProxies.GlyphAdvancesProxy, (void *)ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetCombiningClassDelegate(CombiningClassDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMultiUserData(del, destroy, this); HarfBuzzApi.hb_unicode_funcs_set_combining_class_func( Handle, DelegateProxies.CombiningClassProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void SetGeneralCategoryDelegate(GeneralCategoryDelegate del, ReleaseDelegate destroy = null) { VerifyParameters(del); var ctx = DelegateProxies.CreateMultiUserData(del, destroy, this); HarfBuzzApi.hb_unicode_funcs_set_general_category_func( Handle, DelegateProxies.GeneralCategoryProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public void Release() { if (_release == null) { _release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(_unknownVTable->Release, typeof(ReleaseDelegate)); } _release(Self); _library.Free(); }
private Blob GetTable(Face face, Tag tag) { var size = Typeface.GetTableSize(tag); var data = Marshal.AllocCoTaskMem(size); var releaseDelegate = new ReleaseDelegate(() => Marshal.FreeCoTaskMem(data)); return(Typeface.TryGetTableData(tag, 0, size, data) ? new Blob(data, size, MemoryMode.ReadOnly, releaseDelegate) : null); }
public int Release() { if (_release == null) { _release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(_unknownVTable->Release, typeof(ReleaseDelegate)); } int count = _release(Self); return(count); }
public ReleaseHook(IDisposable comObject, IntPtr comInterface) { this.comObject = comObject; var vtable = Marshal.ReadIntPtr(comInterface); var releaseOffset = 2 * IntPtr.Size; var releasePointer = Marshal.ReadIntPtr(vtable, releaseOffset); originalRelease = Marshal.GetDelegateForFunctionPointer<ReleaseDelegate>(releasePointer); releaseDetour = ReleaseDetour; var releaseDetourPointer = Marshal.GetFunctionPointerForDelegate(releaseDetour); Marshal.WriteIntPtr(vtable, releaseOffset, releaseDetourPointer); }
public Face(GetTableDelegate getTable, object context, ReleaseDelegate destroy) : this(IntPtr.Zero) { if (getTable == null) { throw new ArgumentNullException(nameof(getTable)); } var ctx = DelegateProxies.CreateMulti <GetTableDelegate> ((_, t, __) => getTable.Invoke(this, t, context), context, destroy); Handle = HarfBuzzApi.hb_face_create_for_tables(DelegateProxies.GetTableDelegateProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti); }
public virtual IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseRelease) { List <object> cashSales = new List <object>(); foreach (ARCashSale cashSale in adapter.Get <ARCashSale>()) { cashSales.Add(cashSale); } asynchronousProcess = false; Base.Save.Press(); asynchronousProcess = true; return(baseRelease(new PXAdapter(new PXView.Dummy(Base, adapter.View.BqlSelect, cashSales)))); }
public Face(GetTableDelegate getTable, ReleaseDelegate destroy) : this(IntPtr.Zero) { if (getTable == null) { throw new ArgumentNullException(nameof(getTable)); } Handle = HarfBuzzApi.hb_face_create_for_tables( DelegateProxies.GetTableDelegateProxy, DelegateProxies.CreateMultiUserData(getTable, destroy, this), DelegateProxies.ReleaseDelegateProxyForMulti); }
/// <summary> /// Release an IUnknown pointer. /// </summary> /// <param name="pUnk">A pointer to the IUnknown interface to release.</param> /// <returns>The result of pUnk->Release().</returns> public static unsafe int Release(IntPtr pUnk) { if (pUnk == IntPtr.Zero) { return(0); } IUnknownVTable *vtable = *(IUnknownVTable **)pUnk; ReleaseDelegate release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(vtable->Release, typeof(ReleaseDelegate)); return(release(pUnk)); }
public ReleaseHook(IDisposable comObject, IntPtr comInterface) { this.comObject = comObject; var vtable = Marshal.ReadIntPtr(comInterface); var releaseOffset = 2 * IntPtr.Size; var releasePointer = Marshal.ReadIntPtr(vtable, releaseOffset); originalRelease = Marshal.GetDelegateForFunctionPointer <ReleaseDelegate>(releasePointer); releaseDetour = ReleaseDetour; var releaseDetourPointer = Marshal.GetFunctionPointerForDelegate(releaseDetour); Marshal.WriteIntPtr(vtable, releaseOffset, releaseDetourPointer); }
public Face(GetTableDelegate getTable, object context, ReleaseDelegate destroy) : this(IntPtr.Zero) { if (getTable == null) { throw new ArgumentNullException(nameof(getTable)); } var ctx = new NativeDelegateContext( new object[] { context, this }, new Delegate[] { destroy, getTable }); Handle = HarfBuzzApi.hb_face_create_for_tables(table_func, ctx.NativeContext, DestroyFunction.NativePointer); }
private CcwHook(IDisposable comObject, IntPtr comInterface, IntPtr originalInterface, CcwWrappers wrappers) { this.comObject = comObject; this.originalInterface = originalInterface; this.wrappers = wrappers; queryInterfaceDetour = QueryInterfaceDetour; releaseDetour = ReleaseDetour; var vtable = Marshal.ReadIntPtr(comInterface); var originalQueryInterfacePointer = Marshal.ReadIntPtr(vtable, 0 * IntPtr.Size); var originalReleasePointer = Marshal.ReadIntPtr(vtable, 2 * IntPtr.Size); originalQueryInterface = Marshal.GetDelegateForFunctionPointer<QueryInterfaceDelegate>(originalQueryInterfacePointer); originalRelease = Marshal.GetDelegateForFunctionPointer<ReleaseDelegate>(originalReleasePointer); Marshal.WriteIntPtr(vtable, 0 * IntPtr.Size, Marshal.GetFunctionPointerForDelegate(queryInterfaceDetour)); Marshal.WriteIntPtr(vtable, 2 * IntPtr.Size, Marshal.GetFunctionPointerForDelegate(releaseDetour)); }
private CcwHook(IDisposable comObject, IntPtr comInterface, IntPtr originalInterface, CcwWrappers wrappers) { this.comObject = comObject; this.originalInterface = originalInterface; this.wrappers = wrappers; queryInterfaceDetour = QueryInterfaceDetour; releaseDetour = ReleaseDetour; var vtable = Marshal.ReadIntPtr(comInterface); var originalQueryInterfacePointer = Marshal.ReadIntPtr(vtable, 0 * IntPtr.Size); var originalReleasePointer = Marshal.ReadIntPtr(vtable, 2 * IntPtr.Size); originalQueryInterface = Marshal.GetDelegateForFunctionPointer <QueryInterfaceDelegate>(originalQueryInterfacePointer); originalRelease = Marshal.GetDelegateForFunctionPointer <ReleaseDelegate>(originalReleasePointer); Marshal.WriteIntPtr(vtable, 0 * IntPtr.Size, Marshal.GetFunctionPointerForDelegate(queryInterfaceDetour)); Marshal.WriteIntPtr(vtable, 2 * IntPtr.Size, Marshal.GetFunctionPointerForDelegate(releaseDetour)); }
private void SetupIUnknownMethods() { /* Read the COM v-table pointer */ IntPtr pVtable = Marshal.ReadIntPtr(m_comPointer); const int ADDREF_VTABLE_INDEX = 0; const int RELEASE_VTABLE_INDEX = 1; const int QUERYINTERFACE_VTABLE_INDEX = 2; /* Get the function pointer */ IntPtr pFunc = Marshal.ReadIntPtr(pVtable, ADDREF_VTABLE_INDEX * IntPtr.Size); /* Cast the function pointer to a .NET delegate */ AddRefMethod = (AddRefDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(AddRefDelegate)); /* Rinse and repeat */ pFunc = Marshal.ReadIntPtr(pVtable, RELEASE_VTABLE_INDEX * IntPtr.Size); ReleaseMethod = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(ReleaseDelegate)); pFunc = Marshal.ReadIntPtr(pVtable, QUERYINTERFACE_VTABLE_INDEX * IntPtr.Size); QueryInterfaceMethod = (QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(QueryInterfaceDelegate)); }
internal static void SetFunctions(CallbackDelegate callback, ReleaseDelegate release) { Callback = callback; Release = release; }
static Win32DnD() { // Required for all other OLE functions to work Win32OleInitialize(IntPtr.Zero); // We reuse those DragDropEventArgs = new DragEventArgs(new DataObject(DataFormats.FileDrop, new string[0]), 0, 0, 0, DragDropEffects.None, DragDropEffects.None); DragFeedbackEventArgs = new GiveFeedbackEventArgs(DragDropEffects.None, true); DragContinueEventArgs = new QueryContinueDragEventArgs(0, false, DragAction.Continue); DragFormats = new ArrayList(); DragFormatArray = new FORMATETC[0]; DragMediums = new ArrayList(); // Set up delegates // IDataObject DOQueryInterface = new QueryInterfaceDelegate(ComIDataObject.QueryInterface); DOAddRef = new AddRefDelegate(ComIDataObject.AddRef); DORelease = new ReleaseDelegate(ComIDataObject.Release); GetData = new GetDataDelegate(ComIDataObject.GetData); GetDataHere = new GetDataHereDelegate(ComIDataObject.GetDataHere); QueryGetData = new QueryGetDataDelegate(ComIDataObject.QueryGetData); GetCanonicalFormatEtc = new GetCanonicalFormatEtcDelegate(ComIDataObject.GetCanonicalFormatEtc); SetData = new SetDataDelegate(ComIDataObject.SetData); EnumFormatEtc = new EnumFormatEtcDelegate(ComIDataObject.EnumFormatEtc); DAdvise = new DAdviseDelegate(ComIDataObject.DAdvise); DUnadvise = new DUnadviseDelegate(ComIDataObject.DUnadvise); EnumDAdvise = new EnumDAdviseDelegate(ComIDataObject.EnumDAdvise); // IDropSource DSQueryInterface = new QueryInterfaceDelegate(ComIDropSource.QueryInterface); DSAddRef = new AddRefDelegate(ComIDropSource.AddRef); DSRelease = new ReleaseDelegate(ComIDropSource.Release); QueryContinueDrag = new QueryContinueDragDelegate(ComIDropSource.QueryContinueDrag); GiveFeedback = new GiveFeedbackDelegate(ComIDropSource.GiveFeedback); // IDropTarget DTQueryInterface = new QueryInterfaceDelegate(ComIDropTarget.QueryInterface); DTAddRef = new AddRefDelegate(ComIDropTarget.AddRef); DTRelease = new ReleaseDelegate(ComIDropTarget.Release); DragEnter = new DragEnterDelegate(ComIDropTarget.DragEnter); DragOver = new DragOverDelegate(ComIDropTarget.DragOver); DragLeave = new DragLeaveDelegate(ComIDropTarget.DragLeave); Drop = new DropDelegate(ComIDropTarget.Drop); }
public Releaser(ReleaseDelegate release) { Assert.NotNull(release); _release = release; }
public void Dispose() { if (_release != null) { _release(); _release = null; } }
public void ReleaseMarshalledDelegates() { releaseDetour = null; queryInterfaceDetour = null; }
public void ReleaseMarshalledDelegate() { releaseDetour = null; }
public static IntPtr Create( QueryInterfaceDelegate queryInterface, AddRefDelegate addRef, ReleaseDelegate release, BarDelegate bar) { var instance = new ManualVTable { QueryInterface = Marshal.GetFunctionPointerForDelegate(queryInterface), AddRef = Marshal.GetFunctionPointerForDelegate(addRef), Release = Marshal.GetFunctionPointerForDelegate(release), Bar = Marshal.GetFunctionPointerForDelegate(bar) }; var marshalledInstance = Marshal.AllocHGlobal(Marshal.SizeOf(instance)); Marshal.StructureToPtr(instance, marshalledInstance, false); return marshalledInstance; }