コード例 #1
0
        /// <include file='doc\COM2TypeInfoProcessor.uex' path='docs/doc[@for="Com2TypeInfoProcessor.GetNameDispId"]/*' />
        /// <devdoc>
        /// Retrieve the dispid of the property that we are to use as the name
        /// member.  In this case, the grid will put parens around the name.
        /// </devdoc>
        public static int GetNameDispId(UnsafeNativeMethods.IDispatch obj)
        {
            int dispid = NativeMethods.DISPID_UNKNOWN;

            string[] names = null;

            ComNativeDescriptor cnd = ComNativeDescriptor.Instance;
            bool succeeded          = false;

            // first try to find one with a valid value
            cnd.GetPropertyValue(obj, "__id", ref succeeded);

            if (succeeded)
            {
                names = new string[] { "__id" };
            }
            else
            {
                cnd.GetPropertyValue(obj, NativeMethods.ActiveX.DISPID_Name, ref succeeded);
                if (succeeded)
                {
                    dispid = NativeMethods.ActiveX.DISPID_Name;
                }
                else
                {
                    cnd.GetPropertyValue(obj, "Name", ref succeeded);
                    if (succeeded)
                    {
                        names = new string[] { "Name" };
                    }
                }
            }

            // now get the dispid of the one that worked...
            if (names != null)
            {
                int[] pDispid = new int[] { NativeMethods.DISPID_UNKNOWN };
                Guid  g       = Guid.Empty;
                int   hr      = obj.GetIDsOfNames(ref g, names, 1, SafeNativeMethods.GetThreadLCID(), pDispid);
                if (NativeMethods.Succeeded(hr))
                {
                    dispid = pDispid[0];
                }
            }

            return(dispid);
        }
コード例 #2
0
        public unsafe static DispatchID GetNameDispId(IDispatch obj)
        {
            DispatchID dispid = DispatchID.UNKNOWN;

            string[] names = null;

            ComNativeDescriptor cnd = ComNativeDescriptor.Instance;
            bool succeeded          = false;

            // first try to find one with a valid value
            cnd.GetPropertyValue(obj, "__id", ref succeeded);

            if (succeeded)
            {
                names = new string[] { "__id" };
            }
            else
            {
                cnd.GetPropertyValue(obj, DispatchID.Name, ref succeeded);
                if (succeeded)
                {
                    dispid = DispatchID.Name;
                }
                else
                {
                    cnd.GetPropertyValue(obj, "Name", ref succeeded);
                    if (succeeded)
                    {
                        names = new string[] { "Name" };
                    }
                }
            }

            // now get the dispid of the one that worked...
            if (names is not null)
            {
                DispatchID pDispid = DispatchID.UNKNOWN;
                Guid       g       = Guid.Empty;
                HRESULT    hr      = obj.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &pDispid);
                if (hr.Succeeded())
                {
                    dispid = pDispid;
                }
            }

            return(dispid);
        }
コード例 #3
0
        public static int GetNameDispId(UnsafeNativeMethods.IDispatch obj)
        {
            int num = -1;

            string[]            rgszNames = null;
            ComNativeDescriptor instance  = ComNativeDescriptor.Instance;
            bool succeeded = false;

            instance.GetPropertyValue(obj, "__id", ref succeeded);
            if (succeeded)
            {
                rgszNames = new string[] { "__id" };
            }
            else
            {
                instance.GetPropertyValue(obj, -800, ref succeeded);
                if (succeeded)
                {
                    num = -800;
                }
                else
                {
                    instance.GetPropertyValue(obj, "Name", ref succeeded);
                    if (succeeded)
                    {
                        rgszNames = new string[] { "Name" };
                    }
                }
            }
            if (rgszNames != null)
            {
                int[] rgDispId = new int[] { -1 };
                Guid  empty    = Guid.Empty;
                if (System.Windows.Forms.NativeMethods.Succeeded(obj.GetIDsOfNames(ref empty, rgszNames, 1, SafeNativeMethods.GetThreadLCID(), rgDispId)))
                {
                    num = rgDispId[0];
                }
            }
            return(num);
        }
コード例 #4
0
        private static PropertyDescriptor[] InternalGetProperties(object obj, UnsafeNativeMethods.ITypeInfo typeInfo, int dispidToGet, ref int defaultIndex)
        {
            if (typeInfo == null)
            {
                return(null);
            }
            Hashtable   propInfoList = new Hashtable();
            int         nameDispId   = GetNameDispId((UnsafeNativeMethods.IDispatch)obj);
            bool        addAboutBox  = false;
            StructCache structCache  = new StructCache();

            try
            {
                ProcessFunctions(typeInfo, propInfoList, dispidToGet, nameDispId, ref addAboutBox, structCache);
            }
            catch (ExternalException)
            {
            }
            try
            {
                ProcessVariables(typeInfo, propInfoList, dispidToGet, nameDispId, structCache);
            }
            catch (ExternalException)
            {
            }
            typeInfo = null;
            int count = propInfoList.Count;

            if (addAboutBox)
            {
                count++;
            }
            PropertyDescriptor[] descriptorArray = new PropertyDescriptor[count];
            int hr = 0;

            object[]            retval   = new object[1];
            ComNativeDescriptor instance = ComNativeDescriptor.Instance;

            foreach (PropInfo info in propInfoList.Values)
            {
                if (!info.NonBrowsable)
                {
                    try
                    {
                        hr = instance.GetPropertyValue(obj, info.DispId, retval);
                    }
                    catch (ExternalException exception)
                    {
                        hr = exception.ErrorCode;
                    }
                    if (!System.Windows.Forms.NativeMethods.Succeeded(hr))
                    {
                        info.Attributes.Add(new BrowsableAttribute(false));
                        info.NonBrowsable = true;
                    }
                }
                else
                {
                    hr = 0;
                }
                Attribute[] array = new Attribute[info.Attributes.Count];
                info.Attributes.CopyTo(array, 0);
                descriptorArray[info.Index] = new Com2PropertyDescriptor(info.DispId, info.Name, array, info.ReadOnly != 2, info.ValueType, info.TypeData, !System.Windows.Forms.NativeMethods.Succeeded(hr));
                if (info.IsDefault)
                {
                    int index = info.Index;
                }
            }
            if (addAboutBox)
            {
                descriptorArray[descriptorArray.Length - 1] = new Com2AboutBoxPropertyDescriptor();
            }
            return(descriptorArray);
        }