Esempio n. 1
0
        internal ComEventsSink AddSink(ref Guid iid)
        {
            ComEventsSink sink = new ComEventsSink(this._rcw, iid);

            this._sinks = ComEventsSink.Add(this._sinks, sink);
            return(this._sinks);
        }
Esempio n. 2
0
        internal static ComEventsSink Remove(ComEventsSink sinks, ComEventsSink sink)
        {
            BCLDebug.Assert(sinks != null, "removing event sink from empty sinks collection");
            BCLDebug.Assert(sink != null, "specify event sink is null");

            if (sink == sinks)
            {
                sinks = sinks._next;
            }
            else
            {
                ComEventsSink current = sinks;
                while (current != null && current._next != sink)
                {
                    current = current._next;
                }

                if (current != null)
                {
                    current._next = sink._next;
                }
            }

            sink.Unadvise();

            return(sinks);
        }
Esempio n. 3
0
        public static ComEventsSink?Remove(ComEventsSink sinks, ComEventsSink sink)
        {
            Debug.Assert(sinks != null, "removing event sink from empty sinks collection");
            Debug.Assert(sink != null, "specify event sink is null");

            ComEventsSink?toReturn = sinks;

            if (sink == sinks)
            {
                toReturn = sinks._next;
            }
            else
            {
                ComEventsSink?current = sinks;
                while (current != null && current._next != sink)
                {
                    current = current._next;
                }

                if (current != null)
                {
                    current._next = sink._next;
                }
            }

            sink.Unadvise();

            return(toReturn);
        }
Esempio n. 4
0
 internal static ComEventsSink RemoveAll(ComEventsSink sinks)
 {
     for (; sinks != null; sinks = sinks._next)
     {
         sinks.Unadvise();
     }
     return((ComEventsSink)null);
 }
        internal static ComEventsSink RemoveAll(ComEventsSink sinks) {
            while (sinks != null) {
                sinks.Unadvise();
                sinks = sinks._next;
            }

            return null;
        }
        // it is caller's responsibility to call this method under lock(rcw)
        public ComEventsSink AddSink(ref Guid iid)
        {
            ComEventsSink sink = new ComEventsSink(_rcw, iid);

            _sinks = ComEventsSink.Add(_sinks, sink);

            return(_sinks);
        }
 internal static ComEventsSink RemoveAll(ComEventsSink sinks)
 {
     while (sinks != null)
     {
         sinks.Unadvise();
         sinks = sinks._next;
     }
     return(null);
 }
        internal static ComEventsSink Find(ComEventsSink sinks, ref Guid iid) {

            ComEventsSink sink = sinks;
            while (sink != null && sink._iidSourceItf != iid) {
                sink = sink._next;
            }

            return sink;
        }
        // Token: 0x06006207 RID: 25095 RVA: 0x0014D460 File Offset: 0x0014B660
        internal static ComEventsSink Find(ComEventsSink sinks, ref Guid iid)
        {
            ComEventsSink comEventsSink = sinks;

            while (comEventsSink != null && comEventsSink._iidSourceItf != iid)
            {
                comEventsSink = comEventsSink._next;
            }
            return(comEventsSink);
        }
Esempio n. 10
0
 public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
 {
     rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw);
     lock (rcw)
     {
         ComEventsInfo local_2 = ComEventsInfo.FromObject(rcw);
         ComEventsSink local_3 = local_2.FindSink(ref iid) ?? local_2.AddSink(ref iid);
         (local_3.FindMethod(dispid) ?? local_3.AddMethod(dispid)).AddDelegate(d);
     }
 }
        internal static ComEventsSink Find(ComEventsSink sinks, ref Guid iid)
        {
            ComEventsSink sink = sinks;

            while ((sink != null) && (sink._iidSourceItf != iid))
            {
                sink = sink._next;
            }
            return(sink);
        }
Esempio n. 12
0
        public static ComEventsSink Find(ComEventsSink sinks, ref Guid iid)
        {
            ComEventsSink sink = sinks;

            while (sink != null && sink._iidSourceItf != iid)
            {
                sink = sink._next;
            }

            return(sink);
        }
        /// <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);
            }
        }
Esempio n. 14
0
        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]);
                }
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        /// <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);
            }
        }
Esempio n. 17
0
 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);
     }
 }
        internal static ComEventsSink Remove(ComEventsSink sinks, ComEventsSink sink) {
            BCLDebug.Assert(sinks != null, "removing event sink from empty sinks collection");
            BCLDebug.Assert(sink != null, "specify event sink is null");

            if (sink == sinks) {
                sinks = sinks._next;
            } else {
                ComEventsSink current = sinks;
                while (current != null && current._next != sink)
                    current = current._next;

                if (current != null) {
                    current._next = sink._next;
                }
            }

            sink.Unadvise();

            return sinks;
        } 
 internal static ComEventsSink Remove(ComEventsSink sinks, ComEventsSink sink)
 {
     if (sink == sinks)
     {
         sinks = sinks._next;
     }
     else
     {
         ComEventsSink comEventsSink = sinks;
         while (comEventsSink != null && comEventsSink._next != sink)
         {
             comEventsSink = comEventsSink._next;
         }
         if (comEventsSink != null)
         {
             comEventsSink._next = sink._next;
         }
     }
     sink.Unadvise();
     return(sinks);
 }
 internal static ComEventsSink Remove(ComEventsSink sinks, ComEventsSink sink)
 {
     if (sink == sinks)
     {
         sinks = sinks._next;
     }
     else
     {
         ComEventsSink sink2 = sinks;
         while ((sink2 != null) && (sink2._next != sink))
         {
             sink2 = sink2._next;
         }
         if (sink2 != null)
         {
             sink2._next = sink._next;
         }
     }
     sink.Unadvise();
     return(sinks);
 }
Esempio n. 21
0
        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);
            }
        }
 internal static ComEventsSink Remove(ComEventsSink sinks, ComEventsSink sink)
 {
     if (sink == sinks)
     {
         sinks = sinks._next;
     }
     else
     {
         ComEventsSink sink2 = sinks;
         while ((sink2 != null) && (sink2._next != sink))
         {
             sink2 = sink2._next;
         }
         if (sink2 != null)
         {
             sink2._next = sink._next;
         }
     }
     sink.Unadvise();
     return sinks;
 }
Esempio n. 23
0
        public static ComEventsSink FromRuntimeCallableWrapper(object rcw, Guid sourceIid, bool createIfNotFound)
        {
            List <ComEventsSink> comEventSinks = ComEventSinksContainer.FromRuntimeCallableWrapper(rcw, createIfNotFound);

            if (comEventSinks == null)
            {
                return(null);
            }

            ComEventsSink comEventSink = null;

            lock (comEventSinks)
            {
                foreach (ComEventsSink sink in comEventSinks)
                {
                    if (sink._iidSourceItf == sourceIid)
                    {
                        comEventSink = sink;
                        break;
                    }

                    if (sink._iidSourceItf == Guid.Empty)
                    {
                        // we found a ComEventSink object that
                        // was previously disposed. Now we will reuse it.
                        sink.Initialize(rcw, sourceIid);
                        comEventSink = sink;
                    }
                }

                if (comEventSink == null && createIfNotFound)
                {
                    comEventSink = new ComEventsSink(rcw, sourceIid);
                    comEventSinks.Add(comEventSink);
                }
            }

            return(comEventSink);
        }
Esempio n. 24
0
 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);
     }
 }
Esempio n. 25
0
 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);
     }
 }
Esempio n. 26
0
 public static ComEventsSink Add(ComEventsSink?sinks, ComEventsSink sink)
 {
     sink._next = sinks;
     return(sink);
 }
Esempio n. 27
0
        // it is caller's responsibility to call this method under lock(rcw)
        internal ComEventsSink AddSink(ref Guid iid) {
            ComEventsSink sink = new ComEventsSink(_rcw, iid);
            _sinks = ComEventsSink.Add(_sinks, sink);

            return _sinks;
        }
Esempio n. 28
0
 internal static ComEventsSink Add(ComEventsSink sinks, ComEventsSink sink)
 {
     sink._next = sinks;
     return(sink);
 }
Esempio n. 29
0
 // it is caller's responsibility to call this method under lock(rcw)
 internal ComEventsSink RemoveSink(ComEventsSink sink) {
     _sinks = ComEventsSink.Remove(_sinks, sink);
     return _sinks;
 }
 public ComEventsSink?FindSink(ref Guid iid)
 {
     return(ComEventsSink.Find(_sinks, ref iid));
 }
 internal ComEventsSink AddSink(ref Guid iid)
 {
     ComEventsSink sink = new ComEventsSink(this._rcw, iid);
     this._sinks = ComEventsSink.Add(this._sinks, sink);
     return this._sinks;
 }
 internal static ComEventsSink Add(ComEventsSink sinks, ComEventsSink sink) {
     sink._next = sinks;
     return sink;
 }
 internal ComEventsSink RemoveSink(ComEventsSink sink)
 {
     this._sinks = ComEventsSink.Remove(this._sinks, sink);
     return this._sinks;
 }
Esempio n. 34
0
 internal ComEventsSink RemoveSink(ComEventsSink sink)
 {
     this._sinks = ComEventsSink.Remove(this._sinks, sink);
     return(this._sinks);
 }
Esempio n. 35
0
 internal ComEventsSink FindSink(ref Guid iid)
 {
     return(ComEventsSink.Find(_sinks, ref iid));
 }
Esempio n. 36
0
 // it is caller's responsibility to call this method under lock(rcw)
 internal ComEventsSink RemoveSink(ComEventsSink sink)
 {
     _sinks = ComEventsSink.Remove(_sinks, sink);
     return(_sinks);
 }
        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]);
                }
            }
        }