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());
}
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);
}
}
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);
}
Aggregations