public static ComEventsMethod?Remove(ComEventsMethod methods, ComEventsMethod method) { Debug.Assert(methods != null, "removing method from empty methods collection"); Debug.Assert(method != null, "specify method is null"); if (methods == method) { return(methods._next); } else { ComEventsMethod?current = methods; while (current != null && current._next != method) { current = current._next; } if (current != null) { current._next = method._next; } return(methods); } }
// Token: 0x0600620D RID: 25101 RVA: 0x0014D520 File Offset: 0x0014B720 public ComEventsMethod AddMethod(int dispid) { ComEventsMethod comEventsMethod = new ComEventsMethod(dispid); this._methods = ComEventsMethod.Add(this._methods, comEventsMethod); return(comEventsMethod); }
public ComEventsMethod AddMethod(int dispid) { ComEventsMethod method = new ComEventsMethod(dispid); _methods = ComEventsMethod.Add(_methods, method); return(method); }
internal static ComEventsMethod Find(ComEventsMethod methods, int dispid) { while ((methods != null) && (methods._dispid != dispid)) { methods = methods._next; } return(methods); }
internal static ComEventsMethod Find(ComEventsMethod methods, int dispid) { while (methods != null && methods._dispid != dispid) { methods = methods._next; } return methods; }
public static ComEventsMethod Find(ComEventsMethod methods, int dispid) { while (methods != null && methods._dispid != dispid) { methods = methods._next; } return(methods); }
public void AddHandler(int dispid, object func) { ComEventsMethod method = FindMethod(dispid) ?? AddMethod(dispid); if (func is Delegate d) { method.AddDelegate(d); } else { method.AddDelegate(new SplatCallSite.InvokeDelegate(new SplatCallSite(func).Invoke), wrapArgs: true); } }
/// <summary> /// Adds a delegate to the invocation list of events originating from the COM object. /// </summary> /// <param name="rcw">COM object firing the events the caller would like to respond to</param> /// <param name="iid">identifier of the source interface used by COM object to fire events</param> /// <param name="dispid">dispatch identifier of the method on the source interface</param> /// <param name="d">delegate to invoke when specified COM event is fired</param> public static void Combine(object rcw, Guid iid, int dispid, Delegate d) { lock (rcw) { ComEventsInfo eventsInfo = ComEventsInfo.FromObject(rcw); ComEventsSink sink = eventsInfo.FindSink(ref iid) ?? eventsInfo.AddSink(ref iid); ComEventsMethod method = sink.FindMethod(dispid) ?? sink.AddMethod(dispid); method.AddDelegate(d); } }
unsafe void NativeMethods.IDispatch.Invoke(int dispid, ref Guid riid, int lcid, System.Runtime.InteropServices.ComTypes.INVOKEKIND wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, IntPtr pvarResult, IntPtr pExcepInfo, IntPtr puArgErr) { ComEventsMethod method = this.FindMethod(dispid); if (method == null) { return; } object[] args = new object[pDispParams.cArgs]; int[] numArray = new int[pDispParams.cArgs]; bool[] flagArray = new bool[pDispParams.cArgs]; Variant *variantPtr = (Variant *)(void *)pDispParams.rgvarg; int * numPtr = (int *)(void *)pDispParams.rgdispidNamedArgs; int index1; for (index1 = 0; index1 < pDispParams.cNamedArgs; ++index1) { int index2 = numPtr[index1]; Variant *variant = ComEventsSink.GetVariant(variantPtr + index1); args[index2] = variant->ToObject(); flagArray[index2] = true; numArray[index2] = !variant->IsByRef ? -1 : index1; } int index3 = 0; for (; index1 < pDispParams.cArgs; ++index1) { while (flagArray[index3]) { ++index3; } Variant *variant = ComEventsSink.GetVariant(variantPtr + (pDispParams.cArgs - 1 - index1)); args[index3] = variant->ToObject(); numArray[index3] = !variant->IsByRef ? -1 : pDispParams.cArgs - 1 - index1; ++index3; } object obj = method.Invoke(args); if (pvarResult != IntPtr.Zero) { Marshal.GetNativeVariantForObject(obj, pvarResult); } for (int index2 = 0; index2 < pDispParams.cArgs; ++index2) { int num = numArray[index2]; if (num != -1) { ComEventsSink.GetVariant(variantPtr + num)->CopyFromIndirect(args[index2]); } } }
public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d) { rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw); object obj = rcw; Delegate result; lock (obj) { ComEventsInfo comEventsInfo = ComEventsInfo.Find(rcw); if (comEventsInfo == null) { result = null; } else { ComEventsSink comEventsSink = comEventsInfo.FindSink(ref iid); if (comEventsSink == null) { result = null; } else { ComEventsMethod comEventsMethod = comEventsSink.FindMethod(dispid); if (comEventsMethod == null) { result = null; } else { comEventsMethod.RemoveDelegate(d); if (comEventsMethod.Empty) { comEventsMethod = comEventsSink.RemoveMethod(comEventsMethod); } if (comEventsMethod == null) { comEventsSink = comEventsInfo.RemoveSink(comEventsSink); } if (comEventsSink == null) { Marshal.SetComObjectData(rcw, typeof(ComEventsInfo), null); GC.SuppressFinalize(comEventsInfo); } result = d; } } } } return(result); }
/// <summary> /// Removes a delegate from the invocation list of events originating from the COM object. /// </summary> /// <param name="rcw">COM object the delegate is attached to</param> /// <param name="iid">identifier of the source interface used by COM object to fire events</param> /// <param name="dispid">dispatch identifier of the method on the source interface</param> /// <param name="d">delegate to remove from the invocation list</param> public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d) { lock (rcw) { ComEventsInfo eventsInfo = ComEventsInfo.Find(rcw); if (eventsInfo == null) { return(null); } ComEventsSink sink = eventsInfo.FindSink(ref iid); if (sink == null) { return(null); } ComEventsMethod method = sink.FindMethod(dispid); if (method == null) { return(null); } method.RemoveDelegate(d); if (method.Empty) { // removed the last event handler for this dispid - need to remove dispid handler method = sink.RemoveMethod(method); } if (method == null) { // removed last dispid handler for this sink - need to remove the sink sink = eventsInfo.RemoveSink(sink); } if (sink == null) { // removed last sink for this rcw - need to remove all traces of event info Marshal.SetComObjectData(rcw, typeof(ComEventsInfo), null); GC.SuppressFinalize(eventsInfo); } return(d); } }
internal static ComEventsMethod Remove(ComEventsMethod methods, ComEventsMethod method) { if (methods == method) { methods = methods._next; } else { ComEventsMethod current = methods; while (current != null && current._next != method) current = current._next; if (current != null) current._next = method._next; } return methods; }
internal static ComEventsMethod Remove(ComEventsMethod methods, ComEventsMethod method) { if (methods == method) { methods = methods._next; return(methods); } ComEventsMethod method2 = methods; while ((method2 != null) && (method2._next != method)) { method2 = method2._next; } if (method2 != null) { method2._next = method._next; } return(methods); }
public static void Combine(object rcw, Guid iid, int dispid, Delegate d) { rcw = UnwrapIfTransparentProxy(rcw); lock (rcw) { ComEventsInfo info = ComEventsInfo.FromObject(rcw); ComEventsSink sink = info.FindSink(ref iid); if (sink == null) { sink = info.AddSink(ref iid); } ComEventsMethod method = sink.FindMethod(dispid); if (method == null) { method = sink.AddMethod(dispid); } method.AddDelegate(d); } }
// Token: 0x06006200 RID: 25088 RVA: 0x0014D240 File Offset: 0x0014B440 internal static ComEventsMethod Remove(ComEventsMethod methods, ComEventsMethod method) { if (methods == method) { methods = methods._next; } else { ComEventsMethod comEventsMethod = methods; while (comEventsMethod != null && comEventsMethod._next != method) { comEventsMethod = comEventsMethod._next; } if (comEventsMethod != null) { comEventsMethod._next = method._next; } } return(methods); }
public static void Combine(object rcw, Guid iid, int dispid, Delegate d) { rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw); object obj = rcw; lock (obj) { ComEventsInfo comEventsInfo = ComEventsInfo.FromObject(rcw); ComEventsSink comEventsSink = comEventsInfo.FindSink(ref iid); if (comEventsSink == null) { comEventsSink = comEventsInfo.AddSink(ref iid); } ComEventsMethod comEventsMethod = comEventsSink.FindMethod(dispid); if (comEventsMethod == null) { comEventsMethod = comEventsSink.AddMethod(dispid); } comEventsMethod.AddDelegate(d); } }
public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d) { rcw = UnwrapIfTransparentProxy(rcw); lock (rcw) { ComEventsInfo info = ComEventsInfo.Find(rcw); if (info == null) { return(null); } ComEventsSink sink = info.FindSink(ref iid); if (sink == null) { return(null); } ComEventsMethod method = sink.FindMethod(dispid); if (method == null) { return(null); } method.RemoveDelegate(d); if (method.Empty) { method = sink.RemoveMethod(method); } if (method == null) { sink = info.RemoveSink(sink); } if (sink == null) { Marshal.SetComObjectData(rcw, typeof(ComEventsInfo), null); GC.SuppressFinalize(info); } return(d); } }
public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d) { rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw); lock (rcw) { ComEventsInfo local_2 = ComEventsInfo.Find(rcw); if (local_2 == null) { return((Delegate)null); } ComEventsSink local_3 = local_2.FindSink(ref iid); if (local_3 == null) { return((Delegate)null); } ComEventsMethod local_4 = local_3.FindMethod(dispid); if (local_4 == null) { return((Delegate)null); } local_4.RemoveDelegate(d); if (local_4.Empty) { local_4 = local_3.RemoveMethod(local_4); } if (local_4 == null) { local_3 = local_2.RemoveSink(local_3); } if (local_3 == null) { Marshal.SetComObjectData(rcw, (object)typeof(ComEventsInfo), (object)null); GC.SuppressFinalize((object)local_2); } return(d); } }
public void RemoveHandler(int dispid, object func) { ComEventsMethod sinkEntry = FindMethod(dispid); if (sinkEntry == null) { return; } if (func is Delegate d) { sinkEntry.RemoveDelegate(d); } else { // Remove the delegate from multicast delegate chain. // We will need to find the delegate that corresponds // to the func handler we want to remove. This will be // easy since we Target property of the delegate object // is a ComEventCallContext object. sinkEntry.RemoveDelegates(d => d.Target is SplatCallSite callContext && callContext._callable.Equals(func)); } // If the delegates chain is empty - we can remove // corresponding ComEvenSinkEntry if (sinkEntry.Empty) { RemoveMethod(sinkEntry); } if (_methods == null || _methods.Empty) { Unadvise(); _iidSourceItf = Guid.Empty; } }
public ComEventsMethod FindMethod(int dispid) { return(ComEventsMethod.Find(_methods, dispid)); }
public ComEventsMethod RemoveMethod(ComEventsMethod method) { _methods = ComEventsMethod.Remove(_methods, method); return(_methods); }
unsafe void NativeMethods.IDispatch.Invoke(int dispid, ref Guid riid, int lcid, INVOKEKIND wFlags, ref DISPPARAMS pDispParams, IntPtr pvarResult, IntPtr pExcepInfo, IntPtr puArgErr) { ComEventsMethod comEventsMethod = this.FindMethod(dispid); if (comEventsMethod == null) { return; } object[] array = new object[pDispParams.cArgs]; int[] array2 = new int[pDispParams.cArgs]; bool[] array3 = new bool[pDispParams.cArgs]; Variant *ptr = (Variant *)((void *)pDispParams.rgvarg); int * ptr2 = (int *)((void *)pDispParams.rgdispidNamedArgs); int i; int num; for (i = 0; i < pDispParams.cNamedArgs; i++) { num = ptr2[i]; Variant *variant = ComEventsSink.GetVariant(ptr + i); array[num] = variant->ToObject(); array3[num] = true; if (variant->IsByRef) { array2[num] = i; } else { array2[num] = -1; } } num = 0; while (i < pDispParams.cArgs) { while (array3[num]) { num++; } Variant *variant2 = ComEventsSink.GetVariant(ptr + (pDispParams.cArgs - 1 - i)); array[num] = variant2->ToObject(); if (variant2->IsByRef) { array2[num] = pDispParams.cArgs - 1 - i; } else { array2[num] = -1; } num++; i++; } object obj = comEventsMethod.Invoke(array); if (pvarResult != IntPtr.Zero) { Marshal.GetNativeVariantForObject(obj, pvarResult); } for (i = 0; i < pDispParams.cArgs; i++) { int num2 = array2[i]; if (num2 != -1) { ComEventsSink.GetVariant(ptr + num2)->CopyFromIndirect(array[i]); } } }
public static ComEventsMethod Add(ComEventsMethod?methods, ComEventsMethod method) { method._next = methods; return(method); }
public ComEventsMethod AddMethod(int dispid) { ComEventsMethod method = new ComEventsMethod(dispid); _methods = ComEventsMethod.Add(_methods, method); return method; }
public ComEventsMethod RemoveMethod(ComEventsMethod method) { _methods = ComEventsMethod.Remove(_methods, method); return _methods; }
public ComEventsMethod RemoveMethod(ComEventsMethod method) { this._methods = ComEventsMethod.Remove(this._methods, method); return this._methods; }
internal static ComEventsMethod Add(ComEventsMethod methods, ComEventsMethod method) { method._next = methods; return(method); }
unsafe void NativeMethods.IDispatch.Invoke(int dispid, ref Guid riid, int lcid, System.Runtime.InteropServices.ComTypes.INVOKEKIND wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, IntPtr pvarResult, IntPtr pExcepInfo, IntPtr puArgErr) { ComEventsMethod method = this.FindMethod(dispid); if (method != null) { int num2; object[] args = new object[pDispParams.cArgs]; int[] numArray = new int[pDispParams.cArgs]; bool[] flagArray = new bool[pDispParams.cArgs]; System.Runtime.InteropServices.Variant *rgvarg = (System.Runtime.InteropServices.Variant *)pDispParams.rgvarg; int *rgdispidNamedArgs = (int *)pDispParams.rgdispidNamedArgs; int index = 0; while (index < pDispParams.cNamedArgs) { num2 = rgdispidNamedArgs[index]; args[num2] = (rgvarg + index).ToObject(); flagArray[num2] = true; if ((rgvarg + index).IsByRef) { numArray[num2] = index; } else { numArray[num2] = -1; } index++; } num2 = 0; while (index < pDispParams.cArgs) { while (flagArray[num2]) { num2++; } System.Runtime.InteropServices.Variant *variantPtr2 = rgvarg + ((pDispParams.cArgs - 1) - index); args[num2] = variantPtr2.ToObject(); if (variantPtr2.IsByRef) { numArray[num2] = (pDispParams.cArgs - 1) - index; } else { numArray[num2] = -1; } num2++; index++; } object obj2 = method.Invoke(args); if (pvarResult != IntPtr.Zero) { Marshal.GetNativeVariantForObject(obj2, pvarResult); } for (index = 0; index < pDispParams.cArgs; index++) { int num3 = numArray[index]; if (num3 != -1) { (rgvarg + num3).CopyFromIndirect(args[index]); } } } }
internal static ComEventsMethod Add(ComEventsMethod methods, ComEventsMethod method) { method._next = methods; return method; }
public ComEventsMethod RemoveMethod(ComEventsMethod method) { this._methods = ComEventsMethod.Remove(this._methods, method); return(this._methods); }
unsafe void NativeMethods.IDispatch.Invoke( int dispid, ref Guid riid, int lcid, ComTypes.INVOKEKIND wFlags, ref ComTypes.DISPPARAMS pDispParams, IntPtr pvarResult, IntPtr pExcepInfo, IntPtr puArgErr) { ComEventsMethod method = FindMethod(dispid); if (method == null) { return; } // notice the unsafe pointers we are using. This is to avoid unnecessary // arguments marshalling. see code:ComEventsHelper#ComEventsArgsMarshalling object [] args = new object[pDispParams.cArgs]; int [] byrefsMap = new int[pDispParams.cArgs]; bool [] usedArgs = new bool[pDispParams.cArgs]; Variant *pvars = (Variant *)pDispParams.rgvarg; int * pNamedArgs = (int *)pDispParams.rgdispidNamedArgs; // copy the named args (positional) as specified int i; int pos; for (i = 0; i < pDispParams.cNamedArgs; i++) { pos = pNamedArgs[i]; Variant *pvar = GetVariant(&pvars[i]); args[pos] = pvar->ToObject(); usedArgs[pos] = true; if (pvar->IsByRef) { byrefsMap[pos] = i; } else { byrefsMap[pos] = -1; } } // copy the rest of the arguments in the reverse order pos = 0; for (; i < pDispParams.cArgs; i++) { // find the next unassigned argument while (usedArgs[pos]) { ++pos; } Variant *pvar = GetVariant(&pvars[pDispParams.cArgs - 1 - i]); args[pos] = pvar->ToObject(); if (pvar->IsByRef) { byrefsMap[pos] = pDispParams.cArgs - 1 - i; } else { byrefsMap[pos] = -1; } pos++; } // Do the actual delegate invocation object result; result = method.Invoke(args); // convert result to VARIANT if (pvarResult != IntPtr.Zero) { Marshal.GetNativeVariantForObject(result, pvarResult); } // Now we need to marshal all the byrefs back for (i = 0; i < pDispParams.cArgs; i++) { int idxToPos = byrefsMap[i]; if (idxToPos == -1) { continue; } GetVariant(&pvars[idxToPos])->CopyFromIndirect(args[i]); } }