示例#1
0
        public ObjectInspector(object comObject)
        {
            System.Runtime.InteropServices.ComTypes.ITypeLib ppTLB = null;
            int pIndex = 0;

            _dispatch = comObject as IDispatch;


            if (_dispatch != null)
            {
                _object   = comObject;
                _typeInfo = _dispatch.GetTypeInfo(0, 0);
                _typeInfo.GetTypeAttr(out _pTypeAttr);
                _typeInfo.GetDocumentation(-1,
                                           out _typeName,
                                           out _typeDescription,
                                           out _typeHelpContext,
                                           out _typeHelpFile);
                _typeInfo.GetContainingTypeLib(out ppTLB, out pIndex);
                _comTypeLibrary = new ComTypeLibrary(ppTLB);
            }
            else
            {
                throw new InvalidComObjectException();
            }
        }
示例#2
0
        internal static COM.TYPEATTR GetTypeAttr(COM.ITypeInfo typeinfo)
        {
            IntPtr pTypeAttr;

            typeinfo.GetTypeAttr(out pTypeAttr);
            COM.TYPEATTR typeattr = Marshal.PtrToStructure <COM.TYPEATTR>(pTypeAttr);
            typeinfo.ReleaseTypeAttr(pTypeAttr);
            return(typeattr);
        }
示例#3
0
        internal static ComTypes.TYPEATTR GetTypeAttr(ComTypes.ITypeInfo typeInfo)
        {
            IntPtr pTypeAttr;

            typeInfo.GetTypeAttr(out pTypeAttr);
            var typeAttr = (ComTypes.TYPEATTR)Marshal.PtrToStructure(pTypeAttr, typeof(ComTypes.TYPEATTR));

            typeInfo.ReleaseTypeAttr(pTypeAttr);
            return(typeAttr);
        }
示例#4
0
        /// <summary>
        /// Returns id of an interface
        /// </summary>
        /// <param name="typeInfo">com type informations</param>
        /// <returns>interface id(iid)</returns>
        internal static Guid GetTypeGuid(this COMTypes.ITypeInfo typeInfo)
        {
            IntPtr attribPtr = IntPtr.Zero;

            typeInfo.GetTypeAttr(out attribPtr);
            COMTypes.TYPEATTR Attributes = (COMTypes.TYPEATTR)Marshal.PtrToStructure(attribPtr, typeof(COMTypes.TYPEATTR));
            Guid typeGuid = Attributes.guid;

            typeInfo.ReleaseTypeAttr(attribPtr);
            return(typeGuid);
        }
示例#5
0
        internal static ComTypes.TYPEATTR GetTypeAttrForTypeInfo(ComTypes.ITypeInfo typeInfo)
        {
            IntPtr pAttrs = IntPtr.Zero;

            typeInfo.GetTypeAttr(out pAttrs);

            // GetTypeAttr should never return null, this is just to be safe
            if (pAttrs == IntPtr.Zero)
            {
                throw Error.CannotRetrieveTypeInformation();
            }

            try {
                return((ComTypes.TYPEATTR)Marshal.PtrToStructure(pAttrs, typeof(ComTypes.TYPEATTR)));
            } finally {
                typeInfo.ReleaseTypeAttr(pAttrs);
            }
        }
示例#6
0
        /// <summary>
        /// Creates an entity support list for a proxy
        /// </summary>
        /// <param name="factory">core to perform searching</param>
        /// <param name="comProxy">proxy to analyze</param>
        /// <returns>supported methods and properties as name/kind dictionary</returns>
        /// <exception cref="COMException">Throws generaly if any exception occurs. See inner exception(s) for details</exception>
        internal Dictionary <string, string> GetSupportedEntities(Core factory, object comProxy)
        {
            try
            {
                Guid parentLibraryGuid = CoreFactoryExtensions.GetParentLibraryGuid(factory, comProxy);
                if (Guid.Empty == parentLibraryGuid)
                {
                    return(null);
                }

                string className = TypeDescriptor.GetClassName(comProxy);
                string key       = (parentLibraryGuid.ToString() + className).ToLower();

                Dictionary <string, string> supportList = null;
                if (factory.EntitiesListCache.TryGetValue(key, out supportList))
                {
                    return(supportList);
                }

                supportList = new Dictionary <string, string>();
                IDispatch dispatch = comProxy as IDispatch;
                if (null == dispatch)
                {
                    throw new COMException("Unable to cast underlying proxy to IDispatch.");
                }

                COMTypes.ITypeInfo typeInfo = dispatch.GetTypeInfo(0, 0);
                if (null == typeInfo)
                {
                    throw new COMException("GetTypeInfo returns null.");
                }

                IntPtr typeAttrPointer = IntPtr.Zero;
                typeInfo.GetTypeAttr(out typeAttrPointer);

                COMTypes.TYPEATTR typeAttr = (COMTypes.TYPEATTR)Marshal.PtrToStructure(typeAttrPointer, typeof(COMTypes.TYPEATTR));
                for (int i = 0; i < typeAttr.cFuncs; i++)
                {
                    string            strName, strDocString, strHelpFile;
                    int               dwHelpContext;
                    IntPtr            funcDescPointer = IntPtr.Zero;
                    COMTypes.FUNCDESC funcDesc;
                    typeInfo.GetFuncDesc(i, out funcDescPointer);
                    funcDesc = (COMTypes.FUNCDESC)Marshal.PtrToStructure(funcDescPointer, typeof(COMTypes.FUNCDESC));

                    switch (funcDesc.invkind)
                    {
                    case COMTypes.INVOKEKIND.INVOKE_PROPERTYGET:
                    case COMTypes.INVOKEKIND.INVOKE_PROPERTYPUT:
                    case COMTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                    {
                        typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile);
                        string outValue = "";
                        bool   exists   = supportList.TryGetValue("Property-" + strName, out outValue);
                        if (!exists)
                        {
                            supportList.Add("Property-" + strName, strDocString);
                        }
                        break;
                    }

                    case COMTypes.INVOKEKIND.INVOKE_FUNC:
                    {
                        typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile);
                        string outValue = "";
                        bool   exists   = supportList.TryGetValue("Method-" + strName, out outValue);
                        if (!exists)
                        {
                            supportList.Add("Method-" + strName, strDocString);
                        }
                        break;
                    }
                    }

                    typeInfo.ReleaseFuncDesc(funcDescPointer);
                }

                typeInfo.ReleaseTypeAttr(typeAttrPointer);
                Marshal.ReleaseComObject(typeInfo);

                factory.EntitiesListCache.Add(key, supportList);

                return(supportList);
            }
            catch (Exception exception)
            {
                throw new COMException("An unexpected error occurs.", exception);
            }
        }