Пример #1
0
        internal object GetPropertyValue(object component, string propertyName, ref bool succeeded)
        {
            if (!(component is UnsafeNativeMethods.IDispatch))
            {
                return(null);
            }
            UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch)component;
            string[] rgszNames = new string[] { propertyName };
            int[]    rgDispId  = new int[] { -1 };
            Guid     empty     = Guid.Empty;

            try
            {
                int hr = dispatch.GetIDsOfNames(ref empty, rgszNames, 1, SafeNativeMethods.GetThreadLCID(), rgDispId);
                if ((rgDispId[0] == -1) || System.Windows.Forms.NativeMethods.Failed(hr))
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            return(this.GetPropertyValue(component, rgDispId[0], ref succeeded));
        }
Пример #2
0
        internal object GetPropertyValue(object component, string propertyName, ref bool succeeded)
        {
            if (!(component is UnsafeNativeMethods.IDispatch))
            {
                return(null);
            }

            UnsafeNativeMethods.IDispatch iDispatch = (UnsafeNativeMethods.IDispatch)component;
            string[] names  = new string[] { propertyName };
            int[]    dispid = new int[1];
            dispid[0] = NativeMethods.DISPID_UNKNOWN;
            Guid g = Guid.Empty;

            try
            {
                int hr = iDispatch.GetIDsOfNames(ref g, names, 1, SafeNativeMethods.GetThreadLCID(), dispid);

                if (dispid[0] == NativeMethods.DISPID_UNKNOWN || NativeMethods.Failed(hr))
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            return(GetPropertyValue(component, dispid[0], ref succeeded));
        }
Пример #3
0
        internal unsafe object GetPropertyValue(object component, string propertyName, ref bool succeeded)
        {
            if (!(component is UnsafeNativeMethods.IDispatch))
            {
                return(null);
            }

            UnsafeNativeMethods.IDispatch iDispatch = (UnsafeNativeMethods.IDispatch)component;
            string[]         names  = new string[] { propertyName };
            Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
            Guid             g      = Guid.Empty;

            try
            {
                HRESULT hr = iDispatch.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                if (dispid == Ole32.DispatchID.UNKNOWN || !hr.Succeeded())
                {
                    return(null);
                }

                return(GetPropertyValue(component, dispid, ref succeeded));
            }
            catch
            {
                return(null);
            }
        }
Пример #4
0
        public object InvokeMember(string methodName, params object[] parameter)
        {
            object retVal = null;

            NativeMethods.tagDISPPARAMS dp = new NativeMethods.tagDISPPARAMS();
            dp.rgvarg = IntPtr.Zero;
            try
            {
                UnsafeNativeMethods.IDispatch scriptObject = this.NativeHtmlElement as UnsafeNativeMethods.IDispatch;
                if (scriptObject != null)
                {
                    Guid     g       = Guid.Empty;
                    string[] names   = new string[] { methodName };
                    int[]    dispids = new int[] { NativeMethods.ActiveX.DISPID_UNKNOWN };
                    int      hr      = scriptObject.GetIDsOfNames(ref g, names, 1,
                                                                  SafeNativeMethods.GetThreadLCID(), dispids);
                    if (NativeMethods.Succeeded(hr) && (dispids[0] != NativeMethods.ActiveX.DISPID_UNKNOWN))
                    {
                        // Reverse the arg order below so that parms are read properly thru IDispatch. (
                        if (parameter != null)
                        {
                            // Reverse the parm order so that they read naturally after IDispatch. (
                            Array.Reverse(parameter);
                        }
                        dp.rgvarg            = (parameter == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(parameter);
                        dp.cArgs             = (parameter == null) ? 0 : parameter.Length;
                        dp.rgdispidNamedArgs = IntPtr.Zero;
                        dp.cNamedArgs        = 0;

                        object[] retVals = new object[1];

                        hr = scriptObject.Invoke(dispids[0], ref g, SafeNativeMethods.GetThreadLCID(),
                                                 NativeMethods.DISPATCH_METHOD, dp,
                                                 retVals, new NativeMethods.tagEXCEPINFO(), null);
                        if (hr == NativeMethods.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ClientUtils.IsSecurityOrCriticalException(ex))
                {
                    throw;
                }
            }
            finally
            {
                if (dp.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dp.rgvarg, parameter.Length);
                }
            }
            return(retVal);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        ///  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.
        /// </summary>
        public unsafe static Ole32.DispatchID GetNameDispId(UnsafeNativeMethods.IDispatch obj)
        {
            Ole32.DispatchID dispid = Ole32.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, Ole32.DispatchID.Name, ref succeeded);
                if (succeeded)
                {
                    dispid = Ole32.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 != null)
            {
                Ole32.DispatchID pDispid = Ole32.DispatchID.UNKNOWN;
                Guid             g       = Guid.Empty;
                HRESULT          hr      = obj.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &pDispid);
                if (hr.Succeeded())
                {
                    dispid = pDispid;
                }
            }

            return(dispid);
        }
Пример #7
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);
        }