Search in sources :

Example 21 with IntByReference

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

the class ITypeInfoTest method testGetImplTypeFlags.

@Test
public void testGetImplTypeFlags() {
    ITypeInfo typeInfo = getTypeInfo();
    IntByReference pImplTypeFlags = new IntByReference();
    HRESULT hr = typeInfo.GetImplTypeFlags(new UINT(0), pImplTypeFlags);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());
//System.out.println("GetImplTypeFlags: " + pImplTypeFlags.toString());
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) UINT(com.sun.jna.platform.win32.WinDef.UINT) Test(org.junit.Test)

Example 22 with IntByReference

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

the class Advapi32Test method testSetGetSecurityDescriptorGroup.

public void testSetGetSecurityDescriptorGroup() {
    SECURITY_DESCRIPTOR sd = new SECURITY_DESCRIPTOR(64 * 1024);
    assertTrue(Advapi32.INSTANCE.InitializeSecurityDescriptor(sd, WinNT.SECURITY_DESCRIPTOR_REVISION));
    PSID pSidPut = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
    IntByReference cbSid = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
    assertTrue("Failed to create well-known SID", Advapi32.INSTANCE.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinBuiltinAdministratorsSid, null, pSidPut, cbSid));
    assertTrue(Advapi32.INSTANCE.SetSecurityDescriptorGroup(sd, pSidPut, true));
    BOOLByReference lpbOwnerDefaulted = new BOOLByReference();
    PSIDByReference prSd = new PSIDByReference();
    assertTrue(Advapi32.INSTANCE.GetSecurityDescriptorGroup(sd, prSd, lpbOwnerDefaulted));
    PSID pSidGet = prSd.getValue();
    assertTrue(Advapi32.INSTANCE.EqualSid(pSidPut, pSidGet));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) PSIDByReference(com.sun.jna.platform.win32.WinNT.PSIDByReference) SECURITY_DESCRIPTOR(com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR) PSID(com.sun.jna.platform.win32.WinNT.PSID)

Example 23 with IntByReference

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

the class Advapi32Test method testReadEventLog.

public void testReadEventLog() {
    HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
    IntByReference pnBytesRead = new IntByReference();
    IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
    Memory buffer = new Memory(1);
    assertFalse(Advapi32.INSTANCE.ReadEventLog(h, WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_BACKWARDS_READ, 0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
    assertTrue(pnMinNumberOfBytesNeeded.getValue() > 0);
    assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 24 with IntByReference

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

the class Advapi32Test method testGetSetFileSecurityNoSACL.

public void testGetSetFileSecurityNoSACL() throws Exception {
    int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
    int memSize = 64 * 1024;
    Memory memorySecurity = new Memory(memSize);
    IntByReference sizeNeeded = new IntByReference(0);
    // create a temp file
    File file = createTempFile();
    String filePath = file.getAbsolutePath();
    try {
        assertEquals("GetFileSecurity(" + filePath + ")", true, Advapi32.INSTANCE.GetFileSecurity(filePath, infoType, memorySecurity, memSize, sizeNeeded));
        assertEquals("SetFileSecurity(" + filePath + ")", true, Advapi32.INSTANCE.SetFileSecurity(filePath, infoType, memorySecurity));
    } finally {
        file.delete();
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) File(java.io.File)

Example 25 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jmonkeyengine by jMonkeyEngine.

the class OpenVRUtil method getTrackedDeviceStringProperty.

/**
	 * Get the value of the given string {@link JOpenVRLibrary.ETrackedDeviceProperty property} attached to the given device.
	 * @param system the underlying OpenVR system.
	 * @param deviceIndex the index of the device to query.
	 * @param property the property to query.
	 * @param bufferSize the size of the buffer to use for storing native string.
	 * @return the value of the given string property attached to the given device.
	 * @see OpenVRInput#getTrackedControllerCount()
	 * @see JOpenVRLibrary.ETrackedDeviceProperty
	 * @see #getTrackedDeviceStringProperty(VR_IVRSystem_FnTable, int, int)
	 */
public static String getTrackedDeviceStringProperty(VR_IVRSystem_FnTable system, int deviceIndex, int property, int bufferSize) {
    String str = "";
    int unBufferSize = 256;
    Pointer pchValue = new Memory(unBufferSize);
    IntByReference pError = new IntByReference();
    system.GetStringTrackedDeviceProperty.apply(deviceIndex, property, pchValue, unBufferSize, pError);
    if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_Success) {
        str = pchValue.getString(0);
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_BufferTooSmall) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_CouldNotContactServer) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_InvalidDevice) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_InvalidOperation) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_NotYetAvailable) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_PermissionDenied) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_StringExceedsMaximumLength) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_UnknownProperty) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_ValueNotProvidedByDevice) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_WrongDataType) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else if (pError.getValue() == ETrackedPropertyError.ETrackedPropertyError_TrackedProp_WrongDeviceClass) {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    } else {
        throw new IllegalArgumentException("Cannot access property \"" + getETrackedDevicePropertyString(property) + "\" (" + property + ") for device " + deviceIndex + ": " + getETrackedPropertyErrorString(pError.getValue()) + " (" + pError.getValue() + ")");
    }
    return str;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) Pointer(com.sun.jna.Pointer)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)199 PointerByReference (com.sun.jna.ptr.PointerByReference)38 Memory (com.sun.jna.Memory)33 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)26 File (java.io.File)19 Pointer (com.sun.jna.Pointer)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 PSID (com.sun.jna.platform.win32.WinNT.PSID)13 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)11 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)11 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)8 Advapi32 (com.sun.jna.platform.win32.Advapi32)7 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)6 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)6 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)6 CredHandle (com.sun.jna.platform.win32.Sspi.CredHandle)5