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); }
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); } }
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(); }
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"); }
public void AxHost_AttachInterfaces_Invoke_Nop() { var control = new SubAxHost("00000000-0000-0000-0000-000000000000"); control.AttachInterfaces(); control.AttachInterfaces(); }
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); }
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); }
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); } }
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); }
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; }
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; }
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; }
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; }
public void AxHost_EndInit_Invoke_Nop() { var control = new SubAxHost("00000000-0000-0000-0000-000000000000"); control.EndInit(); control.EndInit(); Assert.False(control.Created); }
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; }
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; }
public void AxHost_DetachSink_Invoke_Nop() { var control = new SubAxHost("00000000-0000-0000-0000-000000000000"); control.DetachSink(); control.DetachSink(); Assert.False(control.Created); }
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; }
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; }
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()); }); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }