Beispiel #1
0
        /// <summary>
        /// Get the IDispatch Typeinfo from CoClass typeinfo.
        /// </summary>
        /// <param name="typeinfo">Reference to the type info to which the type descriptor belongs</param>
        /// <returns>ITypeInfo reference to the Dispatch interface </returns>
        internal static COM.ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(COM.ITypeInfo typeinfo)
        {
            //Get the number of interfaces implemented by this CoClass.
            COM.TYPEATTR typeattr = GetTypeAttr(typeinfo);
            int count = typeattr.cImplTypes;
            int href;
            COM.ITypeInfo interfaceinfo = null;

            //For each interface implemented by this coclass
            for (int i = 0; i < count; i++)
            {
                //Get the type information?
                typeinfo.GetRefTypeOfImplType(i, out href);
                typeinfo.GetRefTypeInfo(href, out interfaceinfo);
                typeattr = GetTypeAttr(interfaceinfo);

                // Is this interface IDispatch compatible interface?
                if (typeattr.typekind == COM.TYPEKIND.TKIND_DISPATCH)
                {
                    return interfaceinfo;
                }

                //Nope. Is this a dual interface
                if ((typeattr.wTypeFlags & COM.TYPEFLAGS.TYPEFLAG_FDUAL) != 0)
                {
                    interfaceinfo = GetDispatchTypeInfoFromCustomInterfaceTypeInfo(interfaceinfo);
                    typeattr = GetTypeAttr(interfaceinfo);

                    if (typeattr.typekind == COM.TYPEKIND.TKIND_DISPATCH)
                    {
                        return interfaceinfo;
                    }
                }
            }
            return null;
        }
Beispiel #2
0
        /// <summary>
        ///  Gets the name of the custom type defined in the type library
        /// </summary>
        /// <param name="typeinfo">ITypeInfo interface of the type</param>
        /// <param name="refptr">reference to the custom type</param>
        /// <returns>name of the custom type</returns>
        private static string GetStringFromCustomType(COM.ITypeInfo typeinfo, IntPtr refptr)
        {
            COM.ITypeInfo custtypeinfo;
            int reftype = unchecked((int)(long)refptr); // note that we cast to long first to prevent overflows; this cast is OK since we are only interested in the lower word

            typeinfo.GetRefTypeInfo(reftype, out custtypeinfo);

            if (custtypeinfo != null)
            {
                String strName, strDoc, strHelp;
                int id;
                custtypeinfo.GetDocumentation(-1, out strName, out strDoc, out id, out strHelp);
                return strName;
            }
            return "UnknownCustomtype";
        }
Beispiel #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeinfo"></param>
        /// <returns></returns>
        internal static COM.ITypeInfo GetDispatchTypeInfoFromCustomInterfaceTypeInfo(COM.ITypeInfo typeinfo)
        {
            int href;
            COM.ITypeInfo dispinfo = null;

            try
            {
                // We need the typeinfo for Dispatch Interface
                typeinfo.GetRefTypeOfImplType(-1, out href);
                typeinfo.GetRefTypeInfo(href, out dispinfo);
            }
            catch (COMException ce)
            {
                //check if the error code is TYPE_E_ELEMENTNOTFOUND.
                //This error code is thrown when we can't IDispatch interface.
                if (ce.HResult != ComUtil.TYPE_E_ELEMENTNOTFOUND)
                {
                    //For other codes, rethrow the exception.
                    throw;
                }
            }
            return dispinfo;
        }