Пример #1
0
        public void GetElementNames(System.Runtime.InteropServices.ComTypes.INVOKEKIND kind, Action <String, Int32> add)
        {
            try {
                for (int i = 0; i < this.TypeAttr.cFuncs; i++)
                {
                    IntPtr pFuncDesc = IntPtr.Zero;
                    System.Runtime.InteropServices.ComTypes.FUNCDESC funcDesc;
                    string strName, strDocString, strHelpFile;
                    int    dwHelpContext;

                    _typeInfo.GetFuncDesc(i, out pFuncDesc);
                    funcDesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)
                               Marshal.PtrToStructure(pFuncDesc, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC));

                    if (funcDesc.invkind == kind)
                    {
                        _typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile);
                        add(strName, funcDesc.cParams);
                    }
                }
            }
            catch (System.Exception ex) {
                throw ex;
            }
        }
Пример #2
0
        internal static void GetInfoFromType(ComTypes.ITypeInfo typeInfo, out string name, out string documentation)
        {
            int    dwHelpContext;
            string strHelpFile;

            typeInfo.GetDocumentation(-1, out name, out documentation, out dwHelpContext, out strHelpFile);
        }
Пример #3
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();
            }
        }
Пример #4
0
 /// <summary>
 /// Gets the name of the method or property defined by funcdesc.
 /// </summary>
 /// <param name="typeinfo">ITypeInfo interface of the type.</param>
 /// <param name="funcdesc">FuncDesc of property of method.</param>
 /// <returns>Name of the method or property.</returns>
 internal static string GetNameFromFuncDesc(COM.ITypeInfo typeinfo, COM.FUNCDESC funcdesc)
 {
     // Get the method or property name.
     string strName, strDoc, strHelp;
     int id;
     typeinfo.GetDocumentation(funcdesc.memid, out strName, out strDoc, out id, out strHelp);
     return strName;
 }
Пример #5
0
        internal static string GetTypeName(ComTypes.ITypeInfo refTypeInfo)
        {
            string refTypeName;
            string strHelpFile;
            int    dwHelpContext;
            string strDocString;

            refTypeInfo.GetDocumentation(-1, out refTypeName, out strDocString, out dwHelpContext, out strHelpFile);
            return(refTypeName);
        }
Пример #6
0
 internal static void GetInfoFromType(ComTypes.ITypeInfo typeInfo, out string name, out string documentation)
 {
     typeInfo.GetDocumentation(-1, out name, out documentation, out int _, out string _);
 }
Пример #7
0
        /// <summary>
        /// Returns a string value representing the type name of the specified COM object.
        /// </summary>
        /// <param name="comObj">A COM object the type name of which to return.</param>
        /// <returns>A string containing the type name.</returns>
        public static string GetTypeName(object comObj)
        {
            if (comObj == null)
            {
                return(String.Empty);
            }

            if (!Marshal.IsComObject(comObj))
            {
                //The specified object is not a COM object
                return(String.Empty);
            }

            IDispatch dispatch = comObj as IDispatch;

            if (dispatch == null)
            {
                //The specified COM object doesn't support getting type information
                return(String.Empty);
            }

            ComTypes.ITypeInfo typeInfo = null;
            try
            {
                try
                {
                    // obtain the ITypeInfo interface from the object
                    dispatch.GetTypeInfo(0, 0, out typeInfo);
                }
                catch (Exception ex)
                {
                    //Cannot get the ITypeInfo interface for the specified COM object
                    return(String.Empty);
                }

                string typeName = "";
                string documentation, helpFile;
                int    helpContext = -1;

                try
                {
                    //retrieves the documentation string for the specified type description
                    typeInfo.GetDocumentation(-1, out typeName, out documentation,
                                              out helpContext, out helpFile);
                }
                catch (Exception ex)
                {
                    // Cannot extract ITypeInfo information
                    return(String.Empty);
                }
                return(typeName);
            }
            catch (Exception ex)
            {
                // Unexpected error
                return(String.Empty);
            }
            finally
            {
                if (typeInfo != null)
                {
                    Marshal.ReleaseComObject(typeInfo);
                }
            }
        }
Пример #8
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);
            }
        }