Search in sources :

Example 21 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference 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 22 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testAccessCheck.

public void testAccessCheck() {
    final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
    mapping.genericRead = new DWORD(FILE_GENERIC_READ);
    mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
    mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
    mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
    final Memory securityDescriptorMemoryPointer = new Memory(1);
    final PRIVILEGE_SET privileges = new PRIVILEGE_SET(1);
    privileges.PrivilegeCount = new DWORD(0);
    final DWORDByReference privilegeLength = new DWORDByReference(new DWORD(privileges.size()));
    final DWORDByReference grantedAccess = new DWORDByReference();
    final BOOLByReference result = new BOOLByReference();
    final boolean status = Advapi32.INSTANCE.AccessCheck(securityDescriptorMemoryPointer, null, new DWORD(FILE_GENERIC_READ), mapping, privileges, privilegeLength, grantedAccess, result);
    assertFalse(status);
    assertFalse(result.getValue().booleanValue());
    assertEquals(WinError.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
}
Also used : BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) PRIVILEGE_SET(com.sun.jna.platform.win32.WinNT.PRIVILEGE_SET) GENERIC_MAPPING(com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) Memory(com.sun.jna.Memory) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Example 23 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testMapGenericExecuteMask.

public void testMapGenericExecuteMask() {
    final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
    mapping.genericRead = new DWORD(FILE_GENERIC_READ);
    mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
    mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
    mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
    final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_EXECUTE));
    Advapi32.INSTANCE.MapGenericMask(rights, mapping);
    assertEquals(FILE_GENERIC_EXECUTE, rights.getValue().intValue());
    assertTrue(GENERIC_EXECUTE != (rights.getValue().intValue() & GENERIC_EXECUTE));
}
Also used : GENERIC_MAPPING(com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Example 24 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testMapGenericReadMask.

public void testMapGenericReadMask() {
    final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
    mapping.genericRead = new DWORD(FILE_GENERIC_READ);
    mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
    mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
    mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
    final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_READ));
    Advapi32.INSTANCE.MapGenericMask(rights, mapping);
    assertEquals(FILE_GENERIC_READ, rights.getValue().intValue());
    assertTrue(GENERIC_READ != (rights.getValue().intValue() & GENERIC_READ));
}
Also used : GENERIC_MAPPING(com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Example 25 with DWORDByReference

use of com.sun.jna.platform.win32.WinDef.DWORDByReference in project jna by java-native-access.

the class Advapi32Test method testMapGenericWriteMask.

public void testMapGenericWriteMask() {
    final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
    mapping.genericRead = new DWORD(FILE_GENERIC_READ);
    mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
    mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
    mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
    final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_WRITE));
    Advapi32.INSTANCE.MapGenericMask(rights, mapping);
    assertEquals(FILE_GENERIC_WRITE, rights.getValue().intValue());
    assertTrue(GENERIC_WRITE != (rights.getValue().intValue() & GENERIC_WRITE));
}
Also used : GENERIC_MAPPING(com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD)

Aggregations

DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)34 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)12 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)11 Test (org.junit.Test)8 Memory (com.sun.jna.Memory)6 GENERIC_MAPPING (com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING)6 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)6 DdeCallback (com.sun.jna.platform.win32.Ddeml.DdeCallback)3 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)3 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)3 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)3 PVOID (com.sun.jna.platform.win32.WinDef.PVOID)3 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)3 Pointer (com.sun.jna.Pointer)2 IID (com.sun.jna.platform.win32.Guid.IID)2 REFIID (com.sun.jna.platform.win32.Guid.REFIID)2 MC_DRIVE_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_DRIVE_TYPE)2 MC_GAIN_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_GAIN_TYPE)2 MC_POSITION_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_POSITION_TYPE)2 MC_SIZE_TYPE (com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_SIZE_TYPE)2