コード例 #1
0
ファイル: ComTypeDesc.cs プロジェクト: mscottford/ironruby
        internal static ComTypeDesc CreateEmptyTypeDesc() {
            ComTypeDesc typeDesc = new ComTypeDesc(null);
            typeDesc._funcs = new Dictionary<string, ComMethodDesc>();
            typeDesc._events = _EmptyEventsDict;

            return typeDesc;
        }
コード例 #2
0
        internal static ComTypeDesc CreateEmptyTypeDesc()
        {
            ComTypeDesc typeDesc = new ComTypeDesc(null);

            typeDesc._funcs  = new Dictionary <string, ComMethodDesc>();
            typeDesc._events = _EmptyEventsDict;

            return(typeDesc);
        }
コード例 #3
0
ファイル: ComTypeDesc.cs プロジェクト: mscottford/ironruby
 internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo) {
     ComTypes.TYPEATTR typeAttr;
     typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);
     if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS) {
         return new ComTypeClassDesc(typeInfo);
     } else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM) {
         return new ComTypeEnumDesc(typeInfo);
     } else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) ||
           (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE)) {
         ComTypeDesc typeDesc = new ComTypeDesc(typeInfo);
         return typeDesc;
     } else {
         throw Error.UnsupportedEnumType();
     }
 }
コード例 #4
0
 internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo)
 {
     ComTypes.TYPEATTR typeAttr;
     typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);
     if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS)
     {
         return(new ComTypeClassDesc(typeInfo));
     }
     else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM)
     {
         return(new ComTypeEnumDesc(typeInfo));
     }
     else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) ||
              (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE))
     {
         ComTypeDesc typeDesc = new ComTypeDesc(typeInfo);
         return(typeDesc);
     }
     else
     {
         throw Error.UnsupportedEnumType();
     }
 }
コード例 #5
0
 internal IDispatchMetaObject(Expression expression, ComTypeDesc wrapperType, IDispatchComObject self)
     : base(expression, Restrictions.Empty, self)
 {
     _wrapperType = wrapperType;
     _self        = self;
 }
コード例 #6
0
        private void EnsureScanDefinedMethods() {
            if (_comTypeDesc != null && _comTypeDesc.Funcs != null)
                return;

            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(_dispatchObject, true);
            if (typeInfo == null) {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null) {
                lock (_CacheComTypeDesc) {
                    if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true &&
                        _comTypeDesc.Funcs != null) {
                        return;
                    }
                }
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo);

            ComMethodDesc getItem = null;
            ComMethodDesc setItem = null;
            Dictionary<string, ComMethodDesc> funcs = new Dictionary<string, ComMethodDesc>(typeAttr.cFuncs);
            Dictionary<string, ComMethodDesc> puts = new Dictionary<string, ComMethodDesc>();
            Dictionary<string, ComMethodDesc> putrefs = new Dictionary<string, ComMethodDesc>();
            Set<int> usedDispIds = new Set<int>();

            for (int definedFuncIndex = 0; definedFuncIndex < typeAttr.cFuncs; definedFuncIndex++) {
                IntPtr funcDescHandleToRelease = IntPtr.Zero;

                try {
                    ComTypes.FUNCDESC funcDesc;
                    GetFuncDescForDescIndex(typeInfo, definedFuncIndex, out funcDesc, out funcDescHandleToRelease);

                    if ((funcDesc.wFuncFlags & (int)ComTypes.FUNCFLAGS.FUNCFLAG_FRESTRICTED) != 0) {
                        // This function is not meant for the script user to use.
                        continue;
                    }

                    ComMethodDesc method = new ComMethodDesc(typeInfo, funcDesc);

                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT) != 0) {
                        puts.Add(method.Name, method);
                        continue;
                    }
                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF) != 0) {
                        putrefs.Add(method.Name, method);
                        continue;
                    }

                    usedDispIds.Add(funcDesc.memid);

                    if (funcDesc.memid == ComDispIds.DISPID_NEWENUM) {
                        funcs.Add("GetEnumerator", method);
                        continue;
                    }

                    funcs.Add(method.Name, method);

                    // for the special dispId == 0, we need to store the method descriptor 
                    // for the Do(GetItem) binder. 
                    if (funcDesc.memid == ComDispIds.DISPID_VALUE) {
                        getItem = method;
                    }
                } finally {
                    if (funcDescHandleToRelease != IntPtr.Zero) {
                        typeInfo.ReleaseFuncDesc(funcDescHandleToRelease);
                    }
                }
            }

            ProcessPut(funcs, puts, usedDispIds, ref setItem);
            ProcessPut(funcs, putrefs, usedDispIds, ref setItem);

            lock (_CacheComTypeDesc) {
                ComTypeDesc cachedTypeDesc;
                if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc)) {
                    _comTypeDesc = cachedTypeDesc;
                } else {
                    _comTypeDesc = typeDesc;
                    _CacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }
                _comTypeDesc.Funcs = funcs;
                _comTypeDesc.Puts = puts;
                _comTypeDesc.PutRefs = putrefs;
                _comTypeDesc.GetItem = getItem;
                _comTypeDesc.SetItem = setItem;
            }
        }
コード例 #7
0
        private void EnsureScanDefinedEvents() {

            // _comTypeDesc.Events is null if we have not yet attempted
            // to scan the object for events.
            if (_comTypeDesc != null && _comTypeDesc.Events != null) {
                return;
            }

            // check type info in the type descriptions cache
            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(_dispatchObject, true);
            if (typeInfo == null) {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null) {
                lock (_CacheComTypeDesc) {
                    if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true &&
                        _comTypeDesc.Events != null) {
                        return;
                    }
                }
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo);

            ComTypes.ITypeInfo classTypeInfo = null;
            Dictionary<string, ComEventDesc> events = null;

            var cpc = RuntimeCallableWrapper as ComTypes.IConnectionPointContainer;
            if (cpc == null) {
                // No ICPC - this object does not support events
                events = ComTypeDesc.EmptyEvents;
            } else if ((classTypeInfo = GetCoClassTypeInfo(this.RuntimeCallableWrapper, typeInfo)) == null) {
                // no class info found - this object may support events
                // but we could not discover those
                Debug.Assert(false, "object support IConnectionPoint but no class info found");
                events = ComTypeDesc.EmptyEvents;
            } else {
                events = new Dictionary<string, ComEventDesc>();

                ComTypes.TYPEATTR classTypeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(classTypeInfo);
                for (int i = 0; i < classTypeAttr.cImplTypes; i++) {
                    int hRefType;
                    classTypeInfo.GetRefTypeOfImplType(i, out hRefType);

                    ComTypes.ITypeInfo interfaceTypeInfo;
                    classTypeInfo.GetRefTypeInfo(hRefType, out interfaceTypeInfo);

                    ComTypes.IMPLTYPEFLAGS flags;
                    classTypeInfo.GetImplTypeFlags(i, out flags);
                    if ((flags & ComTypes.IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) != 0) {
                        ScanSourceInterface(interfaceTypeInfo, ref events);
                    }
                }

                if (events.Count == 0) {
                    events = ComTypeDesc.EmptyEvents;
                }
            }

            lock (_CacheComTypeDesc) {
                ComTypeDesc cachedTypeDesc;
                if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc)) {
                    _comTypeDesc = cachedTypeDesc;
                } else {
                    _comTypeDesc = typeDesc;
                    _CacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }
                _comTypeDesc.Events = events;
            }

        }
コード例 #8
0
        private void EnsureScanDefinedMethods()
        {
            if (_comTypeDesc != null && _comTypeDesc.Funcs != null)
            {
                return;
            }

            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(_dispatchObject, true);
            if (typeInfo == null)
            {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null)
            {
                lock (_CacheComTypeDesc) {
                    if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true &&
                        _comTypeDesc.Funcs != null)
                    {
                        return;
                    }
                }
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo);

            ComMethodDesc getItem = null;
            ComMethodDesc setItem = null;
            Dictionary <string, ComMethodDesc> funcs   = new Dictionary <string, ComMethodDesc>(typeAttr.cFuncs);
            Dictionary <string, ComMethodDesc> puts    = new Dictionary <string, ComMethodDesc>();
            Dictionary <string, ComMethodDesc> putrefs = new Dictionary <string, ComMethodDesc>();
            Set <int> usedDispIds = new Set <int>();

            for (int definedFuncIndex = 0; definedFuncIndex < typeAttr.cFuncs; definedFuncIndex++)
            {
                IntPtr funcDescHandleToRelease = IntPtr.Zero;

                try {
                    ComTypes.FUNCDESC funcDesc;
                    GetFuncDescForDescIndex(typeInfo, definedFuncIndex, out funcDesc, out funcDescHandleToRelease);

                    if ((funcDesc.wFuncFlags & (int)ComTypes.FUNCFLAGS.FUNCFLAG_FRESTRICTED) != 0)
                    {
                        // This function is not meant for the script user to use.
                        continue;
                    }

                    ComMethodDesc method = new ComMethodDesc(typeInfo, funcDesc);

                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT) != 0)
                    {
                        puts.Add(method.Name, method);
                        continue;
                    }
                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF) != 0)
                    {
                        putrefs.Add(method.Name, method);
                        continue;
                    }

                    usedDispIds.Add(funcDesc.memid);

                    if (funcDesc.memid == ComDispIds.DISPID_NEWENUM)
                    {
                        funcs.Add("GetEnumerator", method);
                        continue;
                    }

                    funcs.Add(method.Name, method);

                    // for the special dispId == 0, we need to store the method descriptor
                    // for the Do(GetItem) binder.
                    if (funcDesc.memid == ComDispIds.DISPID_VALUE)
                    {
                        getItem = method;
                    }
                } finally {
                    if (funcDescHandleToRelease != IntPtr.Zero)
                    {
                        typeInfo.ReleaseFuncDesc(funcDescHandleToRelease);
                    }
                }
            }

            ProcessPut(funcs, puts, usedDispIds, ref setItem);
            ProcessPut(funcs, putrefs, usedDispIds, ref setItem);

            lock (_CacheComTypeDesc) {
                ComTypeDesc cachedTypeDesc;
                if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc))
                {
                    _comTypeDesc = cachedTypeDesc;
                }
                else
                {
                    _comTypeDesc = typeDesc;
                    _CacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }
                _comTypeDesc.Funcs   = funcs;
                _comTypeDesc.Puts    = puts;
                _comTypeDesc.PutRefs = putrefs;
                _comTypeDesc.GetItem = getItem;
                _comTypeDesc.SetItem = setItem;
            }
        }
コード例 #9
0
        private void EnsureScanDefinedEvents()
        {
            // _comTypeDesc.Events is null if we have not yet attempted
            // to scan the object for events.
            if (_comTypeDesc != null && _comTypeDesc.Events != null)
            {
                return;
            }

            // check type info in the type descriptions cache
            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(_dispatchObject, true);
            if (typeInfo == null)
            {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null)
            {
                lock (_CacheComTypeDesc) {
                    if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true &&
                        _comTypeDesc.Events != null)
                    {
                        return;
                    }
                }
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo);

            ComTypes.ITypeInfo classTypeInfo         = null;
            Dictionary <string, ComEventDesc> events = null;

            var cpc = RuntimeCallableWrapper as ComTypes.IConnectionPointContainer;

            if (cpc == null)
            {
                // No ICPC - this object does not support events
                events = ComTypeDesc.EmptyEvents;
            }
            else if ((classTypeInfo = GetCoClassTypeInfo(this.RuntimeCallableWrapper, typeInfo)) == null)
            {
                // no class info found - this object may support events
                // but we could not discover those
                Debug.Assert(false, "object support IConnectionPoint but no class info found");
                events = ComTypeDesc.EmptyEvents;
            }
            else
            {
                events = new Dictionary <string, ComEventDesc>();

                ComTypes.TYPEATTR classTypeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(classTypeInfo);
                for (int i = 0; i < classTypeAttr.cImplTypes; i++)
                {
                    int hRefType;
                    classTypeInfo.GetRefTypeOfImplType(i, out hRefType);

                    ComTypes.ITypeInfo interfaceTypeInfo;
                    classTypeInfo.GetRefTypeInfo(hRefType, out interfaceTypeInfo);

                    ComTypes.IMPLTYPEFLAGS flags;
                    classTypeInfo.GetImplTypeFlags(i, out flags);
                    if ((flags & ComTypes.IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) != 0)
                    {
                        ScanSourceInterface(interfaceTypeInfo, ref events);
                    }
                }

                if (events.Count == 0)
                {
                    events = ComTypeDesc.EmptyEvents;
                }
            }

            lock (_CacheComTypeDesc) {
                ComTypeDesc cachedTypeDesc;
                if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc))
                {
                    _comTypeDesc = cachedTypeDesc;
                }
                else
                {
                    _comTypeDesc = typeDesc;
                    _CacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }
                _comTypeDesc.Events = events;
            }
        }
コード例 #10
0
 internal IDispatchMetaObject(Expression expression, ComTypeDesc wrapperType, IDispatchComObject self)
     : base(expression, Restrictions.Empty, self) {
     _wrapperType = wrapperType;
     _self = self;
 }