示例#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 COM.FUNCDESC GetFuncDesc(COM.ITypeInfo typeinfo, int index)
        {
            IntPtr pFuncDesc;

            typeinfo.GetFuncDesc(index, out pFuncDesc);
            COM.FUNCDESC funcdesc = Marshal.PtrToStructure <COM.FUNCDESC>(pFuncDesc);
            typeinfo.ReleaseFuncDesc(pFuncDesc);
            return(funcdesc);
        }
示例#3
0
        private static IEnumerable <ComTypes.FUNCDESC> GetFuncDescs(ComTypes.ITypeInfo typeInfo, ComTypes.TYPEATTR typeAttr)
        {
            for (var iFunc = 0; iFunc < typeAttr.cFuncs; iFunc++)
            {
                IntPtr pFuncDesc;
                typeInfo.GetFuncDesc(iFunc, out pFuncDesc);
                var funcDesc = (ComTypes.FUNCDESC)Marshal.PtrToStructure(pFuncDesc, typeof(ComTypes.FUNCDESC));
                yield return(funcDesc);

                typeInfo.ReleaseFuncDesc(pFuncDesc);
            }
        }
示例#4
0
        private static void GetFuncDescForDescIndex(ComTypes.ITypeInfo typeInfo, int funcIndex, out ComTypes.FUNCDESC funcDesc, out IntPtr funcDescHandle)
        {
            IntPtr pFuncDesc = IntPtr.Zero;

            typeInfo.GetFuncDesc(funcIndex, out pFuncDesc);

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

            funcDesc       = (ComTypes.FUNCDESC)Marshal.PtrToStructure(pFuncDesc, typeof(ComTypes.FUNCDESC));
            funcDescHandle = pFuncDesc;
        }
示例#5
0
        /// <summary>
        /// Converts a MethodBase[] into a MethodInformation[]
        /// </summary>
        /// <returns>the ComMethodInformation[] corresponding to methods</returns>
        internal static ComMethodInformation[] GetMethodInformationArray(COM.ITypeInfo typeInfo, Collection <int> methods, bool skipLastParameters)
        {
            int methodCount = methods.Count;
            int count       = 0;

            ComMethodInformation[] returnValue = new ComMethodInformation[methodCount];

            foreach (int index in methods)
            {
                IntPtr pFuncDesc;
                typeInfo.GetFuncDesc(index, out pFuncDesc);
                COM.FUNCDESC funcdesc = ClrFacade.PtrToStructure <COM.FUNCDESC>(pFuncDesc);
                returnValue[count++] = ComUtil.GetMethodInformation(funcdesc, skipLastParameters);
                typeInfo.ReleaseFuncDesc(pFuncDesc);
            }
            return(returnValue);
        }
示例#6
0
        internal string GetDefinition()
        {
            IntPtr pFuncDesc = IntPtr.Zero;

            try
            {
                _typeInfo.GetFuncDesc(GetFuncDescIndex(), out pFuncDesc);
                COM.FUNCDESC funcdesc = Marshal.PtrToStructure <COM.FUNCDESC>(pFuncDesc);

                return(ComUtil.GetMethodSignatureFromFuncDesc(_typeInfo, funcdesc, !IsGettable));
            }
            finally
            {
                if (pFuncDesc != IntPtr.Zero)
                {
                    _typeInfo.ReleaseFuncDesc(pFuncDesc);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Returns the different method overloads signatures.
        /// </summary>
        /// <returns></returns>
        internal Collection <string> MethodDefinitions()
        {
            Collection <string> result = new Collection <string>();

            foreach (int index in _methods)
            {
                IntPtr pFuncDesc;

                _typeInfo.GetFuncDesc(index, out pFuncDesc);
                COM.FUNCDESC funcdesc = Marshal.PtrToStructure <COM.FUNCDESC>(pFuncDesc);

                string signature = ComUtil.GetMethodSignatureFromFuncDesc(_typeInfo, funcdesc, false);
                result.Add(signature);

                _typeInfo.ReleaseFuncDesc(pFuncDesc);
            }

            return(result);
        }
示例#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);
            }
        }