示例#1
0
        private void Initialize()
        {
            using (ComTypeInfo.tracer.TraceMethod())
            {
                if (this.typeinfo == null)
                {
                    return;
                }
                System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = ComTypeInfo.GetTypeAttr(this.typeinfo);
                this.guid = typeAttr.guid;
                for (int firstUserMethod = ComTypeInfo.FindFirstUserMethod(typeAttr); firstUserMethod < (int)typeAttr.cFuncs; ++firstUserMethod)
                {
                    System.Runtime.InteropServices.ComTypes.FUNCDESC funcDesc = ComTypeInfo.GetFuncDesc(this.typeinfo, firstUserMethod);
                    string nameFromFuncDesc = ComUtil.GetNameFromFuncDesc(this.typeinfo, funcDesc);
                    switch (funcDesc.invkind)
                    {
                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_FUNC:
                        this.AddMethod(nameFromFuncDesc, firstUserMethod);
                        break;

                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYGET:
                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT:
                    case System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                        this.AddProperty(nameFromFuncDesc, funcDesc, firstUserMethod);
                        break;
                    }
                }
            }
        }
示例#2
0
        internal static ITypeInfo GetDispatchTypeInfoFromCoClassTypeInfo(ITypeInfo typeinfo)
        {
            int       cImplTypes = (int)ComTypeInfo.GetTypeAttr(typeinfo).cImplTypes;
            ITypeInfo ppTI       = (ITypeInfo)null;

            for (int index = 0; index < cImplTypes; ++index)
            {
                int href;
                typeinfo.GetRefTypeOfImplType(index, out href);
                typeinfo.GetRefTypeInfo(href, out ppTI);
                System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = ComTypeInfo.GetTypeAttr(ppTI);
                if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                {
                    return(ppTI);
                }
                if ((typeAttr.wTypeFlags & System.Runtime.InteropServices.ComTypes.TYPEFLAGS.TYPEFLAG_FDUAL) != (System.Runtime.InteropServices.ComTypes.TYPEFLAGS) 0)
                {
                    ppTI = ComTypeInfo.GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTI);
                    if (ComTypeInfo.GetTypeAttr(ppTI).typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_DISPATCH)
                    {
                        return(ppTI);
                    }
                }
            }
            return((ITypeInfo)null);
        }
示例#3
0
        internal static ComTypeInfo GetDispatchTypeInfo(object comObject)
        {
            ComTypeInfo comTypeInfo = (ComTypeInfo)null;

            if (comObject is IDispatch dispatch)
            {
                ITypeInfo ppTInfo = (ITypeInfo)null;
                dispatch.GetTypeInfo(0, 0, out ppTInfo);
                if (ppTInfo != null)
                {
                    System.Runtime.InteropServices.ComTypes.TYPEATTR typeAttr = ComTypeInfo.GetTypeAttr(ppTInfo);
                    if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_INTERFACE)
                    {
                        ppTInfo = ComTypeInfo.GetDispatchTypeInfoFromCustomInterfaceTypeInfo(ppTInfo);
                    }
                    if (typeAttr.typekind == System.Runtime.InteropServices.ComTypes.TYPEKIND.TKIND_COCLASS)
                    {
                        ppTInfo = ComTypeInfo.GetDispatchTypeInfoFromCoClassTypeInfo(ppTInfo);
                    }
                    comTypeInfo = new ComTypeInfo(ppTInfo);
                }
            }
            return(comTypeInfo);
        }