Search in sources :

Example 11 with DISPID

use of com.sun.jna.platform.win32.OaIdl.DISPID in project jna by java-native-access.

the class ProxyObject method setProperty.

@Override
public <T> void setProperty(DISPID dispId, T value) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    VARIANT v = Convert.toVariant(value);
    WinNT.HRESULT hr = this.oleMethod(OleAuto.DISPATCH_PROPERTYPUT, null, this.getRawDispatch(), dispId, v);
    // Free value allocated by Convert#toVariant
    Convert.free(v, value);
    COMUtils.checkRC(hr);
}
Also used : WinNT(com.sun.jna.platform.win32.WinNT) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT)

Example 12 with DISPID

use of com.sun.jna.platform.win32.OaIdl.DISPID in project jna by java-native-access.

the class ProxyObject method setProperty.

// --------------------- IDispatch ------------------------------
@Override
public <T> void setProperty(String name, T value) {
    DISPID dispID = resolveDispId(this.getRawDispatch(), name);
    setProperty(dispID, value);
}
Also used : DISPID(com.sun.jna.platform.win32.OaIdl.DISPID)

Example 13 with DISPID

use of com.sun.jna.platform.win32.OaIdl.DISPID in project jna by java-native-access.

the class ComEventCallbacks_Test method testComEventCallback.

@Test
public void testComEventCallback() throws InterruptedException {
    VARIANT.ByReference pVarResult = new VARIANT.ByReference();
    IntByReference puArgErr = new IntByReference();
    EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
    HRESULT hr;
    DISPPARAMS.ByReference pDispParams;
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(new VARIANT[] { new VARIANT(true) });
    pDispParams.setRgdispidNamedArgs(new DISPID[] { OaIdl.DISPID_PROPERTYPUT });
    // Visible-Prioperty
    hr = ieDispatch.Invoke(dispIdVisible.getValue(), niid, lcid, propertyPutFlags, pDispParams, null, null, null);
    COMUtils.checkRC(hr);
    // query for ConnectionPointContainer
    Unknown unk = new Unknown(ieApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    hr = unk.QueryInterface(new REFIID(IID_IConnectionPointContainer), ppCpc);
    COMUtils.checkRC(hr);
    ConnectionPointContainer cpc = new ConnectionPointContainer(ppCpc.getValue());
    // find connection point for DWebBrowserEvents2
    REFIID riid = new REFIID(IID_DWebBrowserEvents2);
    PointerByReference ppCp = new PointerByReference();
    hr = cpc.FindConnectionPoint(riid, ppCp);
    COMUtils.checkRC(hr);
    final ConnectionPoint cp = new ConnectionPoint(ppCp.getValue());
    IID cp_iid = new IID();
    hr = cp.GetConnectionInterface(cp_iid);
    COMUtils.checkRC(hr);
    final DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
    final DWORDByReference pdwCookie = new DWORDByReference();
    HRESULT hr1 = cp.Advise(listener, pdwCookie);
    COMUtils.checkRC(hr1);
    // Advise make several callbacks into the object passed in - at this
    // point QueryInterface must have be called multiple times
    Assert.assertTrue(listener.QueryInterface_called);
    // Call Navigate with URL https://github.com/java-native-access/jna
    String navigateURL = "https://github.com/java-native-access/jna";
    String blockedURL = "http://www.google.de";
    VARIANT[] arguments = new VARIANT[] { new VARIANT(navigateURL) };
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(arguments);
    hr = ieDispatch.Invoke(dispIdNavigate.getValue(), niid, lcid, methodFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    for (int i = 0; i < 10; i++) {
        if (listener.navigateComplete2Called) {
            break;
        }
        Thread.sleep(1000);
    }
    // At this point the call to Navigate before should be complete
    Assert.assertTrue(listener.navigateComplete2Called);
    // Navidate complete should have brought us to github
    Assert.assertEquals(navigateURL, listener.navigateComplete2String);
    listener.navigateComplete2Called = false;
    listener.navigateComplete2String = null;
    listener.blockNavigation = true;
    arguments = new VARIANT[] { new VARIANT(blockedURL) };
    pDispParams = new DISPPARAMS.ByReference();
    pDispParams.setArgs(arguments);
    hr = ieDispatch.Invoke(dispIdNavigate.getValue(), niid, lcid, methodFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    // wait 10 seconds to ensure navigation won't happen
    for (int i = 0; i < 10; i++) {
        if (listener.navigateComplete2Called) {
            break;
        }
        Thread.sleep(1000);
    }
    // Naviation will be blocked - so NavigateComplete can't be called
    Assert.assertFalse("NavigateComplete Handler was called although it should be blocked", listener.navigateComplete2Called);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) EXCEPINFO(com.sun.jna.platform.win32.OaIdl.EXCEPINFO) REFIID(com.sun.jna.platform.win32.Guid.REFIID) WString(com.sun.jna.WString) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) VARIANT_BOOLByReference(com.sun.jna.platform.win32.OaIdl.VARIANT_BOOLByReference) UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) PointerByReference(com.sun.jna.ptr.PointerByReference) DISPPARAMS(com.sun.jna.platform.win32.OleAuto.DISPPARAMS) Test(org.junit.Test)

Example 14 with DISPID

use of com.sun.jna.platform.win32.OaIdl.DISPID in project jna by java-native-access.

the class IDispatchTest method testIDispatchDISPID.

@Test
public void testIDispatchDISPID() throws InterruptedException {
    DISPID locationURL = new DISPID(0x000000d3);
    DISPID visible = new DISPID(0x00000192);
    DISPID quit = new DISPID(0x0000012c);
    DISPID navigate2 = new DISPID(0x000001f4);
    ComInternetExplorerIDispatch ieApp = factory.createObject(ComInternetExplorerIDispatch.class);
    // Test getting property
    assertFalse(ieApp.getProperty(Boolean.class, visible));
    // Test setting property
    ieApp.setProperty(visible, Boolean.TRUE);
    assertTrue(ieApp.getProperty(Boolean.class, visible));
    // Check navigate function and with that the method invocation
    assertTrue(ieApp.getProperty(String.class, locationURL).isEmpty());
    ieApp.invokeMethod(Void.class, navigate2, "https://github.com/java-native-access/");
    // Check max. 10s if Navigation happend
    boolean navigationHappend = false;
    for (int i = 0; i < 50; i++) {
        String url = ieApp.getProperty(String.class, locationURL);
        if (!url.isEmpty()) {
            navigationHappend = true;
            break;
        } else {
            Thread.sleep(200);
        }
    }
    ieApp.invokeMethod(Void.class, quit);
    assertTrue(navigationHappend);
}
Also used : DISPID(com.sun.jna.platform.win32.OaIdl.DISPID) Test(org.junit.Test)

Aggregations

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)9 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)8 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)7 REFIID (com.sun.jna.platform.win32.Guid.REFIID)6 DISPID (com.sun.jna.platform.win32.OaIdl.DISPID)6 IntByReference (com.sun.jna.ptr.IntByReference)6 PointerByReference (com.sun.jna.ptr.PointerByReference)6 WString (com.sun.jna.WString)5 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)4 Variant (com.sun.jna.platform.win32.Variant)4 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)4 COMException (com.sun.jna.platform.win32.COM.COMException)3 EXCEPINFO (com.sun.jna.platform.win32.OaIdl.EXCEPINFO)3 DISPPARAMS (com.sun.jna.platform.win32.OleAuto.DISPPARAMS)3 WinDef (com.sun.jna.platform.win32.WinDef)3 WinNT (com.sun.jna.platform.win32.WinNT)3 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)1 ComEventCallback (com.sun.jna.platform.win32.COM.util.annotation.ComEventCallback)1