Search in sources :

Example 1 with POINT

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

the class ComEventCallbacks_Test method FindConnectionPoint.

@Test
public void FindConnectionPoint() {
    // query for ConnectionPointContainer
    Unknown unk = new Unknown(ieApp.getValue());
    PointerByReference ppCpc = new PointerByReference();
    HRESULT 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);
    // On success the returned pointer must not be null
    Assert.assertNotNull(ppCpc.getPointer());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID) Test(org.junit.Test)

Example 2 with POINT

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

the class Kernel32Test method testDeviceIoControlFsctlReparse.

/**
     * NOTE: Due to process elevation, this test must be run as administrator
     * @throws IOException
     */
public void testDeviceIoControlFsctlReparse() throws IOException {
    Path folder = Files.createTempDirectory("testDeviceIoControlFsctlReparse_FOLDER");
    Path link = Files.createTempDirectory("testDeviceIoControlFsctlReparse_LINK");
    File delFolder = folder.toFile();
    delFolder.deleteOnExit();
    File delLink = link.toFile();
    delLink.deleteOnExit();
    // Required for FSCTL_SET_REPARSE_POINT
    Advapi32Util.Privilege restore = new Advapi32Util.Privilege(WinNT.SE_RESTORE_NAME);
    try {
        restore.enable();
        HANDLE hFile = Kernel32.INSTANCE.CreateFile(link.toAbsolutePath().toString(), WinNT.GENERIC_READ | WinNT.FILE_WRITE_ATTRIBUTES | WinNT.FILE_WRITE_EA, WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE | WinNT.FILE_SHARE_DELETE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_DIRECTORY | WinNT.FILE_FLAG_BACKUP_SEMANTICS | WinNT.FILE_FLAG_OPEN_REPARSE_POINT, null);
        if (WinBase.INVALID_HANDLE_VALUE.equals(hFile)) {
            fail("CreateFile failed with " + Kernel32.INSTANCE.GetLastError());
        }
        try {
            SymbolicLinkReparseBuffer symLinkReparseBuffer = new SymbolicLinkReparseBuffer(folder.getFileName().toString(), folder.getFileName().toString(), Ntifs.SYMLINK_FLAG_RELATIVE);
            REPARSE_DATA_BUFFER lpBuffer = new REPARSE_DATA_BUFFER(WinNT.IO_REPARSE_TAG_SYMLINK, (short) 0, symLinkReparseBuffer);
            assertTrue(Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_SET_REPARSE_POINT, lpBuffer.getPointer(), lpBuffer.getSize(), null, 0, null, null));
            Memory p = new Memory(REPARSE_DATA_BUFFER.sizeOf());
            IntByReference lpBytes = new IntByReference();
            assertTrue(Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, null, 0, p, (int) p.size(), lpBytes, null));
            // Is a reparse point
            lpBuffer = new REPARSE_DATA_BUFFER(p);
            assertTrue(lpBytes.getValue() > 0);
            assertTrue(lpBuffer.ReparseTag == WinNT.IO_REPARSE_TAG_SYMLINK);
            assertEquals(folder.getFileName().toString(), lpBuffer.u.symLinkReparseBuffer.getPrintName());
            assertEquals(folder.getFileName().toString(), lpBuffer.u.symLinkReparseBuffer.getSubstituteName());
        } finally {
            Kernel32Util.closeHandle(hFile);
        }
    } finally {
        restore.close();
    }
}
Also used : Path(java.nio.file.Path) REPARSE_DATA_BUFFER(com.sun.jna.platform.win32.Ntifs.REPARSE_DATA_BUFFER) IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) SymbolicLinkReparseBuffer(com.sun.jna.platform.win32.Ntifs.SymbolicLinkReparseBuffer) File(java.io.File) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 3 with POINT

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

the class ProxyObject method advise.

public IComEventCallbackCookie advise(Class<?> comEventCallbackInterface, final IComEventCallbackListener comEventCallbackListener) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    try {
        ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class);
        if (null == comInterfaceAnnotation) {
            throw new COMException("advise: Interface must define a value for either iid via the ComInterface annotation");
        }
        final IID iid = this.getIID(comInterfaceAnnotation);
        final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid);
        // create the dispatch listener
        final IDispatchCallback rawListener = factory.createDispatchCallback(comEventCallbackInterface, comEventCallbackListener);
        // store it the comEventCallback argument, so it is not garbage
        // collected.
        comEventCallbackListener.setDispatchCallbackListener(rawListener);
        // set the dispatch listener to listen to events from the connection
        // point
        final DWORDByReference pdwCookie = new DWORDByReference();
        HRESULT hr = rawCp.Advise(rawListener, pdwCookie);
        // release before check in case check
        int n = rawCp.Release();
        // throws exception
        COMUtils.checkRC(hr);
        // return the cookie so that a call to stop listening can be made
        return new ComEventCallbackCookie(pdwCookie.getValue());
    } catch (Exception e) {
        throw new COMException("Error occured in advise when trying to connect the listener " + comEventCallbackListener, e);
    }
}
Also used : COMException(com.sun.jna.platform.win32.COM.COMException) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) IDispatchCallback(com.sun.jna.platform.win32.COM.IDispatchCallback) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) ComInterface(com.sun.jna.platform.win32.COM.util.annotation.ComInterface) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint) TimeoutException(java.util.concurrent.TimeoutException) COMException(com.sun.jna.platform.win32.COM.COMException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with POINT

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

the class ProxyObject method fetchRawConnectionPoint.

// ---------------------- IConnectionPoint ----------------------
private ConnectionPoint fetchRawConnectionPoint(IID iid) throws InterruptedException, ExecutionException, TimeoutException {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    // query for ConnectionPointContainer
    IConnectionPointContainer cpc = this.queryInterface(IConnectionPointContainer.class);
    Dispatch rawCpcDispatch = (Dispatch) cpc.getRawDispatch();
    final ConnectionPointContainer rawCpc = new ConnectionPointContainer(rawCpcDispatch.getPointer());
    // find connection point for comEventCallback interface
    final REFIID adviseRiid = new REFIID(iid.getPointer());
    final PointerByReference ppCp = new PointerByReference();
    HRESULT hr = rawCpc.FindConnectionPoint(adviseRiid, ppCp);
    COMUtils.checkRC(hr);
    final ConnectionPoint rawCp = new ConnectionPoint(ppCp.getValue());
    return rawCp;
}
Also used : ConnectionPointContainer(com.sun.jna.platform.win32.COM.ConnectionPointContainer) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) IDispatch(com.sun.jna.platform.win32.COM.IDispatch) REFIID(com.sun.jna.platform.win32.Guid.REFIID) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint)

Example 5 with POINT

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

the class User32Test method testGetCursorPos.

@Test
public void testGetCursorPos() {
    POINT cursorPos = new POINT();
    boolean result = User32.INSTANCE.GetCursorPos(cursorPos);
    assertTrue("GetCursorPos should return true", result);
    assertTrue("X coordinate in POINT should be >= 0", cursorPos.x >= 0);
    assertTrue("Y coordinate in POINT should be >= 0", cursorPos.y >= 0);
}
Also used : POINT(com.sun.jna.platform.win32.WinDef.POINT) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 REFIID (com.sun.jna.platform.win32.Guid.REFIID)5 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)5 PointerByReference (com.sun.jna.ptr.PointerByReference)5 POINT (com.sun.jna.platform.win32.WinDef.POINT)4 IID (com.sun.jna.platform.win32.Guid.IID)3 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)3 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)2 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)2 IntByReference (com.sun.jna.ptr.IntByReference)2 Memory (com.sun.jna.Memory)1 Pointer (com.sun.jna.Pointer)1 WString (com.sun.jna.WString)1 COMException (com.sun.jna.platform.win32.COM.COMException)1 ConnectionPointContainer (com.sun.jna.platform.win32.COM.ConnectionPointContainer)1 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)1 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)1 IDispatchCallback (com.sun.jna.platform.win32.COM.IDispatchCallback)1 ComInterface (com.sun.jna.platform.win32.COM.util.annotation.ComInterface)1 GDI32 (com.sun.jna.platform.win32.GDI32)1