ComEventSinkProxy class is responsible for handling QIs for sourceIid on instances of ComEventSink. Background: When a COM even sink advises to a connection point it is supposed to hand over the dispinterface. Now, some hosts will trust the COM client to pass the correct pointer, but some will not. E.g. Excel's implementation of Connection Points will not cause a QI on the pointer that has been passed, however Word will QI the pointer to return the required interface. ComEventSink does not, strongly speaking, implements the interface that it claims to implement - it is just "faking" it by using IReflect. Thus, Word's QIs on the pointer passed to ICP::Advise would fail. To prevent this we take advangate of RealProxy's ability of "dressing up" like other classes and hence successfully respond to QIs for interfaces that it does not really support( it is OK to say "I implement this interface" for event sinks only since the common practice is to use IDistpach.Invoke when calling into event sinks).
Наследование: System.Runtime.Remoting.Proxies.RealProxy
Пример #1
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);
        }
Пример #2
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);
        }