コード例 #1
0
        public ComTypeInfo TryGetComTypeInfo()
        {
            ComTypeInfo comTypeInfo = null;
            IDispatch   dispatch    = null;

            try
            {
                dispatch = TryGetUniqueRCW <IDispatch>();

                if (dispatch != null)
                {
                    comTypeInfo = ComTypeManager.Instance.FromIDispatch(dispatch);
                }
            }
            catch
            {
            }
            finally
            {
                ComPtr.CleanupUniqueRCW(dispatch);
            }


            return(comTypeInfo);
        }
コード例 #2
0
        private ComPropertyInfo[] GetInheriteProperties(ComTypeInfo comTypeInfo)
        {
            List <ComPropertyInfo> list = new List <ComPropertyInfo>();

            for (int i = 0; i < comTypeInfo.ImplementedTypes.Length; i++)
            {
                ComImplementedTypeInfo comImplementedTypeInfo = comTypeInfo.ImplementedTypes[i];

                if (comImplementedTypeInfo.IsSource == false)
                {
                    foreach (ComPropertyInfo comPropertyInfo in comImplementedTypeInfo.ComTypeInfo.Properties)
                    {
                        if (list.FirstOrDefault(x => x.Name.Equals(comPropertyInfo.Name)) == null)
                        {
                            list.Add(comPropertyInfo);
                        }
                    }

                    list.AddRange(GetInheriteProperties(comImplementedTypeInfo.ComTypeInfo));
                }
            }

            list.Sort(delegate(ComPropertyInfo a, ComPropertyInfo b)
            {
                return(a.Name.CompareTo(b.Name));
            });

            return(list.ToArray());
        }
コード例 #3
0
ファイル: ComMemberInfo.cs プロジェクト: abbazs/SolidEdgeSpy
        public ComPropertyInfo(ComTypeInfo parent, ComFunctionInfo[] functions)
            : base(parent)
        {
            _functions.AddRange(functions);

            _name        = functions[0].Name;
            _description = functions[0].Description;
        }
コード例 #4
0
        public bool TryIsCollection()
        {
            ComTypeInfo comTypeInfo = TryGetComTypeInfo();

            if (comTypeInfo != null)
            {
                return(comTypeInfo.IsCollection);
            }

            return(false);
        }
コード例 #5
0
ファイル: ComMemberInfo.cs プロジェクト: abbazs/SolidEdgeSpy
 public ComVariableInfo(ComTypeInfo parent, System.Runtime.InteropServices.ComTypes.VARDESC varDesc, object constantValue)
     : base(parent)
 {
     _varDesc = varDesc;
     _comTypeInfo.GetITypeInfo().GetDocumentation(_varDesc.memid, out _name, out _description, out _helpContext, out _helpFile);
     _constantValue = constantValue;
     if (_description == null)
     {
         _description = String.Empty;
     }
     if (_helpFile == null)
     {
         _helpFile = String.Empty;
     }
 }
コード例 #6
0
ファイル: ComMemberInfo.cs プロジェクト: abbazs/SolidEdgeSpy
        public ComFunctionInfo(ComTypeInfo parent, IntPtr pFuncDesc)
            : base(parent)
        {
            _pFuncDesc = pFuncDesc;
            _funcDesc  = pFuncDesc.ToStructure <System.Runtime.InteropServices.ComTypes.FUNCDESC>();
            _comTypeInfo.GetITypeInfo().GetDocumentation(_funcDesc.memid, out _name, out _description, out _helpContext, out _helpFile);

            if (_description == null)
            {
                _description = String.Empty;
            }
            if (_helpFile == null)
            {
                _helpFile = String.Empty;
            }

            LoadParameters();
        }
コード例 #7
0
        public bool HasComType(string fullName)
        {
            string[] tokens = fullName.Split(new char[] { '.' });

            if (tokens.Length == 2)
            {
                ComTypeLibrary comTypeLibrary = _typeLibraries.Where(x => x.Name.Equals(tokens[0])).FirstOrDefault();
                if (comTypeLibrary != null)
                {
                    ComTypeInfo comTypeInfo = comTypeLibrary.ComTypeInfos.Where(x => x.Name.Equals(tokens[1])).FirstOrDefault();
                    if (comTypeInfo != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #8
0
ファイル: ComHelper.cs プロジェクト: abbazs/SolidEdgeSpy
        public static string TypeDescToString(System.Runtime.InteropServices.ComTypes.TYPEDESC typeDesc, ITypeInfo typeInfo)
        {
            ITypeInfo refTypeInfo = null;
            VarEnum   variantType = (VarEnum)typeDesc.vt;

            System.Runtime.InteropServices.ComTypes.TYPEDESC ptrTypeDesc;

            switch (variantType)
            {
            case VarEnum.VT_PTR:
                ptrTypeDesc = typeDesc.lpValue.ToStructure <System.Runtime.InteropServices.ComTypes.TYPEDESC>();
                return(TypeDescToString(ptrTypeDesc, typeInfo));

            case VarEnum.VT_USERDEFINED:
                //int href = (int)(typeDesc.lpValue.ToInt64() & int.MaxValue);
                //typeInfo.GetRefTypeInfo(href, out refTypeInfo);
                IFixedTypeInfo fixedTypeInfo = (IFixedTypeInfo)typeInfo;
                fixedTypeInfo.GetRefTypeInfo(typeDesc.lpValue, out refTypeInfo);
                ComTypeInfo refComTypeInfo = ComTypeManager.Instance.FromITypeInfo(refTypeInfo);
                return(refComTypeInfo.FullName);

            case VarEnum.VT_SAFEARRAY:
                string s = TypeDescToString(typeDesc.lpValue.ToStructure <System.Runtime.InteropServices.ComTypes.TYPEDESC>(), typeInfo);
                return(String.Format("{0}[]", s));

            case VarEnum.VT_VOID:
                return("void");

            default:
                Type t = VariantTypeToType(variantType);
                if (t != null)
                {
                    return(t.Name);
                }
                break;
            }

            return("");
        }
コード例 #9
0
        public object TryGetFirstAvailableProperty(string[] propertyNames)
        {
            object      value   = null;
            ComTypeInfo comType = TryGetComTypeInfo();

            if (comType != null)
            {
                foreach (string propertyName in propertyNames)
                {
                    ComPropertyInfo comPropertyInfo = comType.Properties.Where(x => x.Name.Equals(propertyName)).FirstOrDefault();

                    if ((comPropertyInfo != null) && (comPropertyInfo.GetFunction != null))
                    {
                        if (MarshalEx.Succeeded(TryInvokePropertyGet(comPropertyInfo.GetFunction.DispId, out value)))
                        {
                            break;
                        }
                    }
                }
            }

            return(value);
        }
コード例 #10
0
        public void LookupAndSelect(string name)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                return;
            }

            string[] tokens = name.Split(new char[] { '.' });

            ComTypeLibrary comTypeLibrary = null;
            ComTypeInfo    comTypeInfo    = null;

            if (tokens.Length == 1)
            {
                comTypeLibrary = _typeLibraries.Where(x => x.Name.Equals(tokens[0])).FirstOrDefault();
                if (comTypeLibrary != null)
                {
                    if (ComTypeLibrarySelected != null)
                    {
                        ComTypeLibrarySelected(this, comTypeLibrary);
                    }
                }
            }
            else if (tokens.Length == 2)
            {
                comTypeLibrary = _typeLibraries.Where(x => x.Name.Equals(tokens[0])).FirstOrDefault();
                if (comTypeLibrary != null)
                {
                    comTypeInfo = comTypeLibrary.ComTypeInfos.Where(x => x.Name.Equals(tokens[1])).FirstOrDefault();
                    if ((comTypeInfo != null) && (ComTypeInfoSelected != null))
                    {
                        ComTypeInfoSelected(this, comTypeInfo);
                    }
                }
            }
        }
コード例 #11
0
 public ComImplementedTypeInfo(ComTypeInfo comTypeInfo, System.Runtime.InteropServices.ComTypes.IMPLTYPEFLAGS implTypeFlags)
 {
     _comTypeInfo   = comTypeInfo;
     _implTypeFlags = implTypeFlags;
 }
コード例 #12
0
ファイル: ComMemberInfo.cs プロジェクト: abbazs/SolidEdgeSpy
 public ComMemberInfo(ComTypeInfo comTypeInfo)
 {
     _comTypeInfo = comTypeInfo;
 }
コード例 #13
0
        public ComTypeInfo LookupUserDefined(System.Runtime.InteropServices.ComTypes.TYPEDESC typeDesc, ComTypeInfo comTypeInfo)
        {
            if (comTypeInfo == null)
            {
                return(null);
            }

            ITypeInfo refTypeInfo = null;
            VarEnum   variantType = (VarEnum)typeDesc.vt;

            if (variantType == VarEnum.VT_USERDEFINED)
            {
                IFixedTypeInfo fixedTypeInfo = (IFixedTypeInfo)comTypeInfo.GetITypeInfo();
                fixedTypeInfo.GetRefTypeInfo(typeDesc.lpValue, out refTypeInfo);
                return(ComTypeManager.Instance.FromITypeInfo(refTypeInfo));
            }

            return(null);
        }
コード例 #14
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if (_propertyDescriptorCollection == null)
            {
                _propertyDescriptorCollection = new PropertyDescriptorCollection(new PropertyDescriptor[] { }, true);

                ComTypeInfo comTypeInfo = TryGetComTypeInfo();

                if (comTypeInfo != null)
                {
                    List <ComPtrPropertyDescriptor> list = new List <ComPtrPropertyDescriptor>();

                    foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.GetProperties(true))
                    {
                        ComFunctionInfo getComFunctionInfo = comPropertyInfo.GetFunction;
                        bool            bReadOnly          = comPropertyInfo.SetFunction == null ? true : false;

                        if (getComFunctionInfo != null)
                        {
                            VarEnum variantType = getComFunctionInfo.ReturnParameter.VariantType;

                            switch (variantType)
                            {
                            case VarEnum.VT_PTR:
                            case VarEnum.VT_DISPATCH:
                            case VarEnum.VT_UNKNOWN:
                                continue;

                            case VarEnum.VT_SAFEARRAY:
                                continue;
                            }

                            // Special case. MailSession is a PITA property that causes modal dialog.
                            if (comPropertyInfo.Name.Equals("MailSession"))
                            {
                                ComPtrProperty comPtrProperty = new ComPtrProperty(comPropertyInfo.Name, comPropertyInfo.Description, 0, typeof(int), variantType, true);
                                list.Add(new ComPtrPropertyDescriptor(ref comPtrProperty, comPropertyInfo, attributes));
                                continue;
                            }

                            object value = null;
                            if (MarshalEx.Succeeded(TryInvokePropertyGet(getComFunctionInfo.DispId, out value)))
                            {
                                Type propertyType = typeof(object);

                                if (value != null)
                                {
                                    propertyType = value.GetType();
                                }
                                else
                                {
                                    bReadOnly = true;
                                }

                                ComPtrProperty comPtrProperty = new ComPtrProperty(comPropertyInfo.Name, comPropertyInfo.Description, value, propertyType, variantType, bReadOnly);
                                list.Add(new ComPtrPropertyDescriptor(ref comPtrProperty, comPropertyInfo, attributes));
                            }
                        }
                    }

#if DEBUG
                    var refCountProperty = new ComPtrProperty("[RefCount]", "", this.RefCount, typeof(int), VarEnum.VT_I4, true);
                    list.Add(new ComPtrPropertyDescriptor(ref refCountProperty, null, attributes));
#endif
                    var pointerProperty = new ComPtrProperty("[Pointer]", "", this.handle, typeof(string), VarEnum.VT_INT, true);
                    list.Add(new ComPtrPropertyDescriptor(ref pointerProperty, null, attributes));

                    _propertyDescriptorCollection = new PropertyDescriptorCollection(list.ToArray());
                }
            }

            return(_propertyDescriptorCollection);
        }