Search in sources :

Example 1 with ShortByReference

use of com.sun.jna.ptr.ShortByReference in project jna by java-native-access.

the class ByReferenceArgumentsTest method testShortByReference.

public void testShortByReference() {
    ShortByReference sref = new ShortByReference();
    lib.incrementInt16ByReference(sref);
    assertEquals("Short argument not modified", 1, sref.getValue());
}
Also used : ShortByReference(com.sun.jna.ptr.ShortByReference)

Example 2 with ShortByReference

use of com.sun.jna.ptr.ShortByReference in project jna by java-native-access.

the class Kernel32Test method testDeviceIoControlFsctlCompression.

public void testDeviceIoControlFsctlCompression() throws IOException {
    File tmp = File.createTempFile("testDeviceIoControlFsctlCompression", "jna");
    tmp.deleteOnExit();
    HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_ALL, WinNT.FILE_SHARE_READ, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
    assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
    try {
        ShortByReference lpBuffer = new ShortByReference();
        IntByReference lpBytes = new IntByReference();
        if (false == Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_GET_COMPRESSION, null, 0, lpBuffer.getPointer(), USHORT.SIZE, lpBytes, null)) {
            fail("DeviceIoControl failed with " + Kernel32.INSTANCE.GetLastError());
        }
        assertEquals(WinNT.COMPRESSION_FORMAT_NONE, lpBuffer.getValue());
        assertEquals(USHORT.SIZE, lpBytes.getValue());
        lpBuffer = new ShortByReference((short) WinNT.COMPRESSION_FORMAT_LZNT1);
        if (false == Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_SET_COMPRESSION, lpBuffer.getPointer(), USHORT.SIZE, null, 0, lpBytes, null)) {
            fail("DeviceIoControl failed with " + Kernel32.INSTANCE.GetLastError());
        }
        if (false == Kernel32.INSTANCE.DeviceIoControl(hFile, FSCTL_GET_COMPRESSION, null, 0, lpBuffer.getPointer(), USHORT.SIZE, lpBytes, null)) {
            fail("DeviceIoControl failed with " + Kernel32.INSTANCE.GetLastError());
        }
        assertEquals(WinNT.COMPRESSION_FORMAT_LZNT1, lpBuffer.getValue());
        assertEquals(USHORT.SIZE, lpBytes.getValue());
    } finally {
        Kernel32Util.closeHandle(hFile);
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) ShortByReference(com.sun.jna.ptr.ShortByReference) File(java.io.File) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 3 with ShortByReference

use of com.sun.jna.ptr.ShortByReference in project jna by java-native-access.

the class Advapi32Test method testSetGetSecurityDescriptorControl.

public void testSetGetSecurityDescriptorControl() {
    SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
    assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
    assertTrue(Advapi32.INSTANCE.SetSecurityDescriptorControl(sd, (short) WinNT.SE_DACL_PROTECTED, (short) WinNT.SE_DACL_PROTECTED));
    ShortByReference pControl = new ShortByReference();
    IntByReference lpdwRevision = new IntByReference();
    assertTrue(Advapi32.INSTANCE.GetSecurityDescriptorControl(sd, pControl, lpdwRevision));
    assertTrue(pControl.getValue() == WinNT.SE_DACL_PROTECTED);
    assertTrue(lpdwRevision.getValue() == WinNT.SECURITY_DESCRIPTOR_REVISION);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) ShortByReference(com.sun.jna.ptr.ShortByReference) SECURITY_DESCRIPTOR(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)

Aggregations

ShortByReference (com.sun.jna.ptr.ShortByReference)3 IntByReference (com.sun.jna.ptr.IntByReference)2 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)1 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)1 File (java.io.File)1