Exemple #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;
        }
Exemple #2
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;
        }