Beispiel #1
0
 internal int GetPropertyValue(object component, int dispid, object[] retval)
 {
     if (!(component is UnsafeNativeMethods.IDispatch))
     {
         return(-2147467262);
     }
     UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch)component;
     try
     {
         int  scode;
         Guid empty = Guid.Empty;
         System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
         try
         {
             scode = dispatch.Invoke(dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 2, new System.Windows.Forms.NativeMethods.tagDISPPARAMS(), retval, pExcepInfo, null);
             if (scode == -2147352567)
             {
                 scode = pExcepInfo.scode;
             }
         }
         catch (ExternalException exception)
         {
             scode = exception.ErrorCode;
         }
         return(scode);
     }
     catch
     {
     }
     return(-2147467259);
 }
Beispiel #2
0
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                object instance = context.Instance;

                if (Marshal.IsComObject(instance) && (instance is UnsafeNativeMethods.IDispatch))
                {
                    UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch)instance;
                    System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
                    Guid empty = Guid.Empty;
                    dispatch.Invoke(-552, ref empty, SafeNativeMethods.GetThreadLCID(), 1, new System.Windows.Forms.NativeMethods.tagDISPPARAMS(), null, pExcepInfo, null);
                }
                return(value);
            }
Beispiel #3
0
        public object GetNativeValue(object component)
        {
            if (component == null)
            {
                return(null);
            }
            if (component is ICustomTypeDescriptor)
            {
                component = ((ICustomTypeDescriptor)component).GetPropertyOwner(this);
            }
            if (((component == null) || !Marshal.IsComObject(component)) || !(component is UnsafeNativeMethods.IDispatch))
            {
                return(null);
            }
            UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch)component;
            object[] pVarResult = new object[1];
            System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
            Guid empty     = Guid.Empty;
            int  errorCode = dispatch.Invoke(this.dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 2, new System.Windows.Forms.NativeMethods.tagDISPPARAMS(), pVarResult, pExcepInfo, null);

            switch (errorCode)
            {
            case 0:
            case 1:
                if ((pVarResult[0] != null) && !Convert.IsDBNull(pVarResult[0]))
                {
                    this.lastValue = pVarResult[0];
                    break;
                }
                this.lastValue = null;
                break;

            case -2147352567:
                return(null);

            default:
                throw new ExternalException(System.Windows.Forms.SR.GetString("DispInvokeFailed", new object[] { "GetValue", errorCode }), errorCode);
            }
            return(this.lastValue);
        }
Beispiel #4
0
        public override void SetValue(object component, object value)
        {
            if (this.readOnly)
            {
                throw new NotSupportedException(System.Windows.Forms.SR.GetString("COM2ReadonlyProperty", new object[] { this.Name }));
            }
            if (component is ICustomTypeDescriptor)
            {
                component = ((ICustomTypeDescriptor)component).GetPropertyOwner(this);
            }
            if (((component != null) && Marshal.IsComObject(component)) && (component is UnsafeNativeMethods.IDispatch))
            {
                if (this.valueConverter != null)
                {
                    bool cancelSet = false;
                    value = this.valueConverter.ConvertManagedToNative(value, this, ref cancelSet);
                    if (cancelSet)
                    {
                        return;
                    }
                }
                UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch)component;
                System.Windows.Forms.NativeMethods.tagDISPPARAMS pDispParams = new System.Windows.Forms.NativeMethods.tagDISPPARAMS();
                System.Windows.Forms.NativeMethods.tagEXCEPINFO  pExcepInfo  = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
                pDispParams.cArgs      = 1;
                pDispParams.cNamedArgs = 1;
                int[]    numArray = new int[] { -3 };
                GCHandle handle   = GCHandle.Alloc(numArray, GCHandleType.Pinned);
                try
                {
                    pDispParams.rgdispidNamedArgs = Marshal.UnsafeAddrOfPinnedArrayElement(numArray, 0);
                    IntPtr ptr = Marshal.AllocCoTaskMem(0x10);
                    SafeNativeMethods.VariantInit(new HandleRef(null, ptr));
                    Marshal.GetNativeVariantForObject(value, ptr);
                    pDispParams.rgvarg = ptr;
                    try
                    {
                        Guid   empty       = Guid.Empty;
                        int    dwMessageId = dispatch.Invoke(this.dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 4, pDispParams, null, pExcepInfo, new IntPtr[1]);
                        string message     = null;
                        if ((dwMessageId == -2147352567) && (pExcepInfo.scode != 0))
                        {
                            dwMessageId = pExcepInfo.scode;
                            message     = pExcepInfo.bstrDescription;
                        }
                        switch (dwMessageId)
                        {
                        case -2147467260:
                        case -2147221492:
                            return;

                        case 0:
                        case 1:
                            this.OnValueChanged(component, EventArgs.Empty);
                            this.lastValue = value;
                            return;
                        }
                        if (dispatch is UnsafeNativeMethods.ISupportErrorInfo)
                        {
                            empty = typeof(UnsafeNativeMethods.IDispatch).GUID;
                            if (System.Windows.Forms.NativeMethods.Succeeded(((UnsafeNativeMethods.ISupportErrorInfo)dispatch).InterfaceSupportsErrorInfo(ref empty)))
                            {
                                UnsafeNativeMethods.IErrorInfo errorInfo = null;
                                UnsafeNativeMethods.GetErrorInfo(0, ref errorInfo);
                                if ((errorInfo != null) && System.Windows.Forms.NativeMethods.Succeeded(errorInfo.GetDescription(null)))
                                {
                                    message = pBstrDescription;
                                }
                            }
                        }
                        else if (message == null)
                        {
                            StringBuilder lpBuffer = new StringBuilder(0x100);
                            if (SafeNativeMethods.FormatMessage(0x1200, System.Windows.Forms.NativeMethods.NullHandleRef, dwMessageId, CultureInfo.CurrentCulture.LCID, lpBuffer, 0xff, System.Windows.Forms.NativeMethods.NullHandleRef) == 0)
                            {
                                message = string.Format(CultureInfo.CurrentCulture, System.Windows.Forms.SR.GetString("DispInvokeFailed", new object[] { "SetValue", dwMessageId }), new object[0]);
                            }
                            else
                            {
                                message = lpBuffer.ToString();
                                while (((message.Length > 0) && (message[message.Length - 1] == '\n')) || (message[message.Length - 1] == '\r'))
                                {
                                    message = message.Substring(0, message.Length - 1);
                                }
                            }
                        }
                        throw new ExternalException(message, dwMessageId);
                    }
                    finally
                    {
                        SafeNativeMethods.VariantClear(new HandleRef(null, ptr));
                        Marshal.FreeCoTaskMem(ptr);
                    }
                }
                finally
                {
                    handle.Free();
                }
            }
        }
 internal int GetPropertyValue(object component, int dispid, object[] retval)
 {
     if (!(component is UnsafeNativeMethods.IDispatch))
     {
         return -2147467262;
     }
     UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch) component;
     try
     {
         int scode;
         Guid empty = Guid.Empty;
         System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
         try
         {
             scode = dispatch.Invoke(dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 2, new System.Windows.Forms.NativeMethods.tagDISPPARAMS(), retval, pExcepInfo, null);
             if (scode == -2147352567)
             {
                 scode = pExcepInfo.scode;
             }
         }
         catch (ExternalException exception)
         {
             scode = exception.ErrorCode;
         }
         return scode;
     }
     catch
     {
     }
     return -2147467259;
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     object instance = context.Instance;
     if (Marshal.IsComObject(instance) && (instance is UnsafeNativeMethods.IDispatch))
     {
         UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch) instance;
         System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
         Guid empty = Guid.Empty;
         dispatch.Invoke(-552, ref empty, SafeNativeMethods.GetThreadLCID(), 1, new System.Windows.Forms.NativeMethods.tagDISPPARAMS(), null, pExcepInfo, null);
     }
     return value;
 }
        public override void SetValue(object component, object value)
        {
            if (this.readOnly)
            {
                throw new NotSupportedException(System.Windows.Forms.SR.GetString("COM2ReadonlyProperty", new object[] { this.Name }));
            }
            if (component is ICustomTypeDescriptor)
            {
                component = ((ICustomTypeDescriptor) component).GetPropertyOwner(this);
            }
            if (((component != null) && Marshal.IsComObject(component)) && (component is UnsafeNativeMethods.IDispatch))
            {
                if (this.valueConverter != null)
                {
                    bool cancelSet = false;
                    value = this.valueConverter.ConvertManagedToNative(value, this, ref cancelSet);
                    if (cancelSet)
                    {
                        return;
                    }
                }
                UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch) component;
                System.Windows.Forms.NativeMethods.tagDISPPARAMS pDispParams = new System.Windows.Forms.NativeMethods.tagDISPPARAMS();
                System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
                pDispParams.cArgs = 1;
                pDispParams.cNamedArgs = 1;
                int[] numArray = new int[] { -3 };
                GCHandle handle = GCHandle.Alloc(numArray, GCHandleType.Pinned);
                try
                {
                    pDispParams.rgdispidNamedArgs = Marshal.UnsafeAddrOfPinnedArrayElement(numArray, 0);
                    IntPtr ptr = Marshal.AllocCoTaskMem(0x10);
                    SafeNativeMethods.VariantInit(new HandleRef(null, ptr));
                    Marshal.GetNativeVariantForObject(value, ptr);
                    pDispParams.rgvarg = ptr;
                    try
                    {
                        Guid empty = Guid.Empty;
                        int dwMessageId = dispatch.Invoke(this.dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 4, pDispParams, null, pExcepInfo, new IntPtr[1]);
                        string message = null;
                        if ((dwMessageId == -2147352567) && (pExcepInfo.scode != 0))
                        {
                            dwMessageId = pExcepInfo.scode;
                            message = pExcepInfo.bstrDescription;
                        }
                        switch (dwMessageId)
                        {
                            case -2147467260:
                            case -2147221492:
                                return;

                            case 0:
                            case 1:
                                this.OnValueChanged(component, EventArgs.Empty);
                                this.lastValue = value;
                                return;
                        }
                        if (dispatch is UnsafeNativeMethods.ISupportErrorInfo)
                        {
                            empty = typeof(UnsafeNativeMethods.IDispatch).GUID;
                            if (System.Windows.Forms.NativeMethods.Succeeded(((UnsafeNativeMethods.ISupportErrorInfo) dispatch).InterfaceSupportsErrorInfo(ref empty)))
                            {
                                UnsafeNativeMethods.IErrorInfo errorInfo = null;
                                UnsafeNativeMethods.GetErrorInfo(0, ref errorInfo);
                                if ((errorInfo != null) && System.Windows.Forms.NativeMethods.Succeeded(errorInfo.GetDescription(null)))
                                {
                                    message = pBstrDescription;
                                }
                            }
                        }
                        else if (message == null)
                        {
                            StringBuilder lpBuffer = new StringBuilder(0x100);
                            if (SafeNativeMethods.FormatMessage(0x1200, System.Windows.Forms.NativeMethods.NullHandleRef, dwMessageId, CultureInfo.CurrentCulture.LCID, lpBuffer, 0xff, System.Windows.Forms.NativeMethods.NullHandleRef) == 0)
                            {
                                message = string.Format(CultureInfo.CurrentCulture, System.Windows.Forms.SR.GetString("DispInvokeFailed", new object[] { "SetValue", dwMessageId }), new object[0]);
                            }
                            else
                            {
                                message = lpBuffer.ToString();
                                while (((message.Length > 0) && (message[message.Length - 1] == '\n')) || (message[message.Length - 1] == '\r'))
                                {
                                    message = message.Substring(0, message.Length - 1);
                                }
                            }
                        }
                        throw new ExternalException(message, dwMessageId);
                    }
                    finally
                    {
                        SafeNativeMethods.VariantClear(new HandleRef(null, ptr));
                        Marshal.FreeCoTaskMem(ptr);
                    }
                }
                finally
                {
                    handle.Free();
                }
            }
        }
        public object GetNativeValue(object component)
        {
            if (component == null)
            {
                return null;
            }
            if (component is ICustomTypeDescriptor)
            {
                component = ((ICustomTypeDescriptor) component).GetPropertyOwner(this);
            }
            if (((component == null) || !Marshal.IsComObject(component)) || !(component is UnsafeNativeMethods.IDispatch))
            {
                return null;
            }
            UnsafeNativeMethods.IDispatch dispatch = (UnsafeNativeMethods.IDispatch) component;
            object[] pVarResult = new object[1];
            System.Windows.Forms.NativeMethods.tagEXCEPINFO pExcepInfo = new System.Windows.Forms.NativeMethods.tagEXCEPINFO();
            Guid empty = Guid.Empty;
            int errorCode = dispatch.Invoke(this.dispid, ref empty, SafeNativeMethods.GetThreadLCID(), 2, new System.Windows.Forms.NativeMethods.tagDISPPARAMS(), pVarResult, pExcepInfo, null);
            switch (errorCode)
            {
                case 0:
                case 1:
                    if ((pVarResult[0] != null) && !Convert.IsDBNull(pVarResult[0]))
                    {
                        this.lastValue = pVarResult[0];
                        break;
                    }
                    this.lastValue = null;
                    break;

                case -2147352567:
                    return null;

                default:
                    throw new ExternalException(System.Windows.Forms.SR.GetString("DispInvokeFailed", new object[] { "GetValue", errorCode }), errorCode);
            }
            return this.lastValue;
        }