Ejemplo n.º 1
0
        public unsafe void IDispatch_Invoke_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;

            Guid    riid       = Guid.Empty;
            var     dispParams = new DISPPARAMS();
            var     varResult  = new object[1];
            var     excepInfo  = new EXCEPINFO();
            uint    argErr     = 0;
            HRESULT hr         = dispatch.Invoke(
                (DispatchID)4,
                &riid,
                Kernel32.GetThreadLocale(),
                DISPATCH.PROPERTYGET,
                &dispParams,
                varResult,
                &excepInfo,
                &argErr
                );

            Assert.Equal(HRESULT.S_OK, hr);
            Assert.Equal(16, GdiHelper.HimetricToPixelY((int)varResult[0]));
            Assert.Equal(0u, argErr);
        }
Ejemplo n.º 2
0
        public unsafe void ITypeInfo_GetVarDesc_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            VARDESC *pVarDesc = null;

            try
            {
                hr = typeInfo.GetVarDesc(3, &pVarDesc);
                Assert.Equal(HRESULT.S_OK, hr);
                Assert.Equal((DispatchID)4, pVarDesc->memid);
                Assert.Equal(IntPtr.Zero, pVarDesc->lpstrSchema);
                Assert.Equal(IntPtr.Zero, pVarDesc->unionMember);
                Assert.Equal(VARENUM.USERDEFINED, pVarDesc->elemdescVar.tdesc.vt);
                Assert.NotEqual(IntPtr.Zero, pVarDesc->elemdescVar.tdesc.union.lpadesc);
                Assert.Equal(IntPtr.Zero, pVarDesc->elemdescVar.paramdesc.pparamdescex);
                Assert.Equal(PARAMFLAG.NONE, pVarDesc->elemdescVar.paramdesc.wParamFlags);
                Assert.Equal(VARFLAGS.FREADONLY, pVarDesc->wVarFlags);
                Assert.Equal(VARKIND.DISPATCH, pVarDesc->varkind);
            }
            finally
            {
                typeInfo.ReleaseVarDesc(pVarDesc);
            }
        }
Ejemplo n.º 3
0
        public unsafe void ITypeInfo_GetNames_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            BSTR *rgszNames = stackalloc BSTR[2];

            rgszNames[0] = new BSTR("Name1");
            rgszNames[1] = new BSTR("Name2");
            uint cNames = 0;

            hr = typeInfo.GetNames((DispatchID)4, rgszNames, 2u, &cNames);
            Assert.Equal(HRESULT.S_OK, hr);
            Assert.Equal("Width", rgszNames[0].String.ToString());
            Assert.Equal("Name2", rgszNames[1].String.ToString());
            Assert.Equal(1u, cNames);

            rgszNames[0].Dispose();
            rgszNames[1].Dispose();
        }
Ejemplo n.º 4
0
        static void Main()
        {
            try
            {
                var o = Activator.CreateInstance(Type.GetTypeFromCLSID(typeof(Server).GUID));
                Console.WriteLine(o.GetType());

                Guid    clsid = typeof(Server).GUID;
                Guid    iid   = new Guid("{00000000-0000-0000-C000-000000000046}");
                HRESULT hr    = CoCreateInstance(
                    ref clsid,
                    IntPtr.Zero,
                    Ole32.CLSCTX.INPROC_SERVER,
                    ref iid,
                    out object res);
                Console.WriteLine(res.GetType());

                var control = new SubAxHost(typeof(Server).GUID.ToString());
                Assert.NotEqual(IntPtr.Zero, control.Handle);
                int invalidatedCallCount = 0;
                control.Invalidated += (sender, e) => invalidatedCallCount++;
                int styleChangedCallCount = 0;
                control.StyleChanged += (sender, e) => styleChangedCallCount++;
                int createdCallCount = 0;
                control.HandleCreated += (sender, e) => createdCallCount++;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Please Love Me");
        }
Ejemplo n.º 5
0
        public void AxHost_AttachInterfaces_Invoke_Nop()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");

            control.AttachInterfaces();
            control.AttachInterfaces();
        }
Ejemplo n.º 6
0
        public void AxHost_Cursor_SetWithChildrenWithCursor_GetReturnsExpected(Cursor value)
        {
            var cursor1 = new Cursor((IntPtr)1);
            var cursor2 = new Cursor((IntPtr)1);
            var child1  = new Control
            {
                Cursor = cursor1
            };
            var child2 = new Control
            {
                Cursor = cursor2
            };
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");

            control.Controls.Add(child1);
            control.Controls.Add(child2);

            control.Cursor = value;
            Assert.Same(value ?? Cursors.Default, control.Cursor);
            Assert.Same(cursor1, child1.Cursor);
            Assert.Same(cursor2, child2.Cursor);

            // Set same.
            control.Cursor = value;
            Assert.Same(value ?? Cursors.Default, control.Cursor);
            Assert.Same(cursor1, child1.Cursor);
            Assert.Same(cursor2, child2.Cursor);
        }
Ejemplo n.º 7
0
        public unsafe void ITypeInfo_Invoke_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            var  dispParams = new DISPPARAMS();
            var  varResult  = new object[1];
            var  excepInfo  = new EXCEPINFO();
            uint argErr     = 0;

            hr = typeInfo.Invoke(
                picture,
                (DispatchID)4,
                DISPATCH.PROPERTYGET,
                &dispParams,
                varResult,
                &excepInfo,
                &argErr
                );
            Assert.Equal(HRESULT.DISP_E_MEMBERNOTFOUND, hr);
            Assert.Null(varResult[0]);
            Assert.Equal(0u, argErr);
        }
Ejemplo n.º 8
0
        public unsafe void ITypeInfo_GetContainingTypeLib_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            IntPtr typeLib = (IntPtr)int.MaxValue;
            uint   index   = uint.MaxValue;

            hr = typeInfo.GetContainingTypeLib(&typeLib, &index);
            try
            {
                Assert.Equal(HRESULT.S_OK, hr);
                Assert.NotEqual(IntPtr.Zero, typeLib);
                Assert.NotEqual(0u, index);
            }
            finally
            {
                Runtime.InteropServices.Marshal.Release(typeLib);
            }
        }
Ejemplo n.º 9
0
        public static void AxHost_ContainingControl_GetWithNonContainerControlParent_ReturnsExpected()
        {
            var parent  = new Control();
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000")
            {
                Parent = parent
            };

            Assert.Null(control.ContainingControl);

            // Call again to check caching.
            Assert.Null(control.ContainingControl);

            // Modify.
            var grandparent = new ContainerControl();

            parent.Parent = grandparent;
            Assert.Same(grandparent, control.ContainingControl);

            // Call again to check caching.
            Assert.Same(grandparent, control.ContainingControl);

            // Remove from chain.
            parent.Parent = null;
            Assert.Same(grandparent, control.ContainingControl);
        }
Ejemplo n.º 10
0
        public void AxHost_Paint_AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            PaintEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.Paint += handler);
            control.Paint -= handler;
        }
Ejemplo n.º 11
0
        public void AxHost_KeyPress_AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            KeyPressEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.KeyPress += handler);
            control.KeyPress -= handler;
        }
Ejemplo n.º 12
0
        public void AxHost_GiveFeedback_AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            GiveFeedbackEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.GiveFeedback += handler);
            control.GiveFeedback -= handler;
        }
Ejemplo n.º 13
0
        public void AxHost_DragEnter_AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            DragEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.DragEnter += handler);
            control.DragEnter -= handler;
        }
Ejemplo n.º 14
0
        public void AxHost_EndInit_Invoke_Nop()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");

            control.EndInit();
            control.EndInit();
            Assert.False(control.Created);
        }
Ejemplo n.º 15
0
        public void AxHost_TextChanged_AddRemove_ThrowsNotSupportedException()
        {
            var          control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            EventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.TextChanged += handler);
            control.TextChanged -= handler;
        }
Ejemplo n.º 16
0
        public void AxHost_QueryAccessibilityHelp__AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            QueryAccessibilityHelpEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.QueryAccessibilityHelp += handler);
            control.QueryAccessibilityHelp -= handler;
        }
Ejemplo n.º 17
0
        public void AxHost_DetachSink_Invoke_Nop()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");

            control.DetachSink();
            control.DetachSink();
            Assert.False(control.Created);
        }
Ejemplo n.º 18
0
        public void AxHost_QueryContinueDrag__AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            QueryContinueDragEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.QueryContinueDrag += handler);
            control.QueryContinueDrag -= handler;
        }
Ejemplo n.º 19
0
        public void AxHost_MouseDown_AddRemove_ThrowsNotSupportedException()
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000");
            MouseEventHandler handler = (sender, e) => { };

            Assert.Throws <NotSupportedException>(() => control.MouseDown += handler);
            control.MouseDown -= handler;
        }
Ejemplo n.º 20
0
 public void AxHost_Handle_GetNotIOleObject_ThrowsInvalidCastException()
 {
     ActivationContext.UsingManifestDo("app.manifest", () =>
     {
         var control = new SubAxHost(typeof(NotIOleObjectClass).GUID.ToString());
         Assert.Throws <InvalidCastException>(() => control.Handle);
         Assert.NotNull(control.GetOcx());
     });
 }
Ejemplo n.º 21
0
        public unsafe void IDispatch_GetTypeInfo_Invoke_Success()
        {
            using var image = new Bitmap(16, 16);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;

            ITypeInfo typeInfo;
            HRESULT   hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);
            Assert.NotNull(typeInfo);
        }
Ejemplo n.º 22
0
        public void AxHost_CreateControl_ValidClsid_Success()
        {
            var control = new SubAxHost("8856f961-340a-11d0-a96b-00c04fd705a2");

            control.CreateControl();
            Assert.True(control.Created);
            Assert.NotEqual(IntPtr.Zero, control.Handle);

            object ocx = control.GetOcx();

            Assert.True(ocx is IWebBrowser2);
        }
Ejemplo n.º 23
0
        public unsafe void IDispatch_GetTypeInfoCount_Invoke_Success()
        {
            using var image = new Bitmap(16, 16);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;

            uint    ctInfo = uint.MaxValue;
            HRESULT hr     = dispatch.GetTypeInfoCount(&ctInfo);

            Assert.Equal(HRESULT.S_OK, hr);
            Assert.Equal(1u, ctInfo);
        }
Ejemplo n.º 24
0
        public void AxHost_Cursor_Set_GetReturnsExpected(Cursor value)
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000")
            {
                Cursor = value
            };

            Assert.Same(value ?? Cursors.Default, control.Cursor);

            // Set same.
            control.Cursor = value;
            Assert.Same(value ?? Cursors.Default, control.Cursor);
        }
Ejemplo n.º 25
0
        public void AxHost_Cursor_SetWithHandle_GetReturnsExpected(Cursor value)
        {
            var control = new SubAxHost("8856f961-340a-11d0-a96b-00c04fd705a2");

            Assert.NotEqual(IntPtr.Zero, control.Handle);

            control.Cursor = value;
            Assert.Same(value ?? Cursors.Default, control.Cursor);

            // Set same.
            control.Cursor = value;
            Assert.Same(value ?? Cursors.Default, control.Cursor);
        }
Ejemplo n.º 26
0
        public void AxHost_ForeColor_Set_GetReturnsExpected(Color value, Color expected)
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000")
            {
                ForeColor = value
            };

            Assert.Equal(expected, control.ForeColor);

            // Set same.
            control.ForeColor = value;
            Assert.Equal(expected, control.ForeColor);
        }
Ejemplo n.º 27
0
        public void AxHost_ImeMode_Set_GetReturnsExpected(ImeMode value)
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000")
            {
                ImeMode = value
            };

            Assert.Equal(value, control.ImeMode);

            // Set same.
            control.ImeMode = value;
            Assert.Equal(value, control.ImeMode);
        }
Ejemplo n.º 28
0
        public void AxHost_Text_Set_GetReturnsExpected(string value)
        {
            var control = new SubAxHost("00000000-0000-0000-0000-000000000000")
            {
                Text = value
            };

            Assert.Equal(value, control.Text);

            // Set same.
            control.Text = value;
            Assert.Equal(value, control.Text);
        }
Ejemplo n.º 29
0
        public void AxHost_EndInit_InvokeWithParent_CreatesControl()
        {
            var parent  = new Control();
            var control = new SubAxHost("8856f961-340a-11d0-a96b-00c04fd705a2")
            {
                Parent = parent
            };

            control.EndInit();
            control.EndInit();
            Assert.True(parent.Created);
            Assert.True(control.Created);
        }
Ejemplo n.º 30
0
        public void AxHost_Text_SetWithHandle_GetReturnsExpected(string value)
        {
            var control = new SubAxHost("8856f961-340a-11d0-a96b-00c04fd705a2");

            Assert.NotEqual(IntPtr.Zero, control.Handle);

            control.Text = value;
            Assert.Equal(value, control.Text);

            // Set same.
            control.Text = value;
            Assert.Equal(value, control.Text);
        }