Search in sources :

Example 21 with Dispatch

use of com.sun.jna.platform.win32.COM.Dispatch in project jna by java-native-access.

the class ComEventCallbacksObjectFactory_Test method testComEventCallback.

@Test
public void testComEventCallback() {
    DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
    CallbackProxy proxy = new CallbackProxy(factory, DWebBrowserEvents2.class, listener);
    REFIID refiid = new REFIID(new IID(DWebBrowserEvents2.IID));
    // precondition: the structures for the listenedToRiid and
    // refiid have to be different (else the PointerType#equals would
    // be enough
    assertFalse(proxy.listenedToRiid.getPointer().equals(refiid.getPointer()));
    // Neverthe less, the QueryInterface method has to return the
    // correct pointer (the IID is relevant, not its wrapper
    PointerByReference interfacePointer = new PointerByReference();
    // Check the "business" interface
    HRESULT hr = proxy.QueryInterface(refiid, interfacePointer);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(interfacePointer.getValue(), proxy.getPointer());
    // IUnknown must be implemented
    hr = proxy.QueryInterface(new REFIID(IID_IUNKNOWN), interfacePointer);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(interfacePointer.getValue(), proxy.getPointer());
    // Currently only Dispatch based callbacks are supported,
    // so this interface must be present to
    hr = proxy.QueryInterface(new REFIID(IID_IDISPATCH), interfacePointer);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(interfacePointer.getValue(), proxy.getPointer());
    // Negative check -- this has to fail, the IID should not be
    // assigned
    hr = proxy.QueryInterface(new REFIID(new IID("{00000000-0000-0000-C000-000000000000}")), interfacePointer);
    assertTrue(COMUtils.FAILED(hr));
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID) Test(org.junit.Test)

Aggregations

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)17 PointerByReference (com.sun.jna.ptr.PointerByReference)14 REFIID (com.sun.jna.platform.win32.Guid.REFIID)12 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 COMException (com.sun.jna.platform.win32.COM.COMException)6 WinNT (com.sun.jna.platform.win32.WinNT)6 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)5 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 IID (com.sun.jna.platform.win32.Guid.IID)5 WString (com.sun.jna.WString)4 ComObject (com.sun.jna.platform.win32.COM.util.annotation.ComObject)4 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)4 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)4 WinDef (com.sun.jna.platform.win32.WinDef)3 IntByReference (com.sun.jna.ptr.IntByReference)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 ComInterface (com.sun.jna.platform.win32.COM.util.annotation.ComInterface)2 GUID (com.sun.jna.platform.win32.Guid.GUID)2