Exemplo n.º 1
0
        private static bool TryGetDispId(IDispatch dispatch, string name, out int dispId)
        {
            RequireReference(dispatch, "dispatch");
            RequireReference(name, "name");

            bool result = false;

            System.Runtime.InteropServices.CustomMarshalers.TypeToTypeInfoMarshaler mar = null;

            Guid iidNull = Guid.Empty;
            int  hr      = dispatch.GetDispId(ref iidNull, ref name, 1, LOCALE_SYSTEM_DEFAULT, out dispId);

            const int DISP_E_UNKNOWNNAME = unchecked ((int)0x80020006); //From WinError.h
            const int DISPID_UNKNOWN     = -1;                          //From OAIdl.idl

            if (hr == S_OK)
            {
                result = true;
            }
            else if (hr == DISP_E_UNKNOWNNAME && dispId == DISPID_UNKNOWN)
            {
                result = false;
            }
            else
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return(result);
        }
Exemplo n.º 2
0
        public List <JqueryObject> NextAll()
        {
            IDispatch dispatch = InvokeMember <IDispatch>("nextAll");

            string  name = "length";
            int     dispId;
            Guid    riid = Guid.Empty;
            HRESULT res  = dispatch.GetDispId(ref riid, name, 1, 0, out dispId);

            int length  = (int)dispatch.GetType().InvokeMember("length", BindingFlags.GetProperty, null, dispatch, null);
            int length2 = (int)dispatch.GetType().InvokeMember("length", BindingFlags.GetProperty, null, dispatch, null);

            for (int index = 0; index < length; index++)
            {
                IDispatch obj = dispatch.GetType().InvokeMember(index.ToString(), BindingFlags.GetProperty, null, dispatch, null) as IDispatch;
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tries to get the DISPID for the requested member name.
        /// </summary>
        /// <param name="dispatch">An object that implements IDispatch.</param>
        /// <param name="name">The name of a member to lookup.</param>
        /// <param name="dispId">If the method returns true, this holds the DISPID on output.
        /// If the method returns false, this value should be ignored.</param>
        /// <returns>True if the member was found and resolved to a DISPID.  False otherwise.</returns>
        private static bool TryGetDispId(IDispatch dispatch, string memberName, out int dispId)
        {
            Guard.ArgumentNotNull(dispatch, "dispatch");
            Guard.ArgumentNotNullOrEmpty(memberName, "memberName");

            bool    result  = false;
            Guid    iidNull = Guid.Empty;
            HRESULT hr      = dispatch.GetDispId(ref iidNull, ref memberName, 1, DispatchConstants.LOCALE_SYSTEM_DEFAULT, out dispId);

            if (hr == HRESULT.S_OK)
            {
                result = true;
            }
            else if (hr == HRESULT.DISP_E_UNKNOWNNAME && dispId == DISPIDConstants.DISPID_UNKNOWN)
            {
                result = false;
            }
            else
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }
            return(result);
        }