예제 #1
0
파일: SinkObject.cs 프로젝트: KOZ60/Samples
        internal void Advise(ComWrapper owner)
        {
            Owner = owner;
            var cpc = owner.ComObject.Target as ComTypes.IConnectionPointContainer;

            cpc.FindConnectionPoint(ref guid, out connectionPoint);
            connectionPoint.Advise(this, out cookie);
            isAdvised = true;
        }
        /// <exception cref="InvalidOperationException">Already attached to IOPCShutdown connection point.</exception>
        public void Connect(object comServer)
        {
            if (IsConnected)
            {
                throw new InvalidOperationException("Already attached to the connection point.");
            }

            var connectionPointContainer = (IConnectionPointContainer)comServer;

            var riid = typeof(T).GUID;

            connectionPointContainer.FindConnectionPoint(ref riid, out _connectionPoint);
            int cookie;

            _connectionPoint.Advise(_sink, out cookie);
            _cookie = cookie;
        }
예제 #3
0
        private void Initialize(object rcw, Guid sourceIid)
        {
            _sourceIid    = sourceIid;
            _adviseCookie = -1;

            Debug.Assert(_connectionPoint == null, "re-initializing event sink w/o unadvising from connection point");

            ComTypes.IConnectionPointContainer cpc = rcw as ComTypes.IConnectionPointContainer;
            if (cpc == null)
            {
                throw Error.COMObjectDoesNotSupportEvents();
            }

            cpc.FindConnectionPoint(ref _sourceIid, out _connectionPoint);
            if (_connectionPoint == null)
            {
                throw Error.COMObjectDoesNotSupportSourceInterface();
            }

            // Read the comments for ComEventSinkProxy about why we need it
            ComEventSinkProxy proxy = new ComEventSinkProxy(this, _sourceIid);

            _connectionPoint.Advise(proxy.GetTransparentProxy(), out _adviseCookie);
        }