Search in sources :

Example 81 with IntByReference

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

the class Rasapi32Util method getIPProjection.

/**
	 * Get the connection's IP projection
	 * @param hrasConn the RAS connection handle
	 * @return the IP projection
	 * @throws Ras32Exception errors
	 */
public static RASPPPIP getIPProjection(HANDLE hrasConn) throws Ras32Exception {
    RASPPPIP pppIpProjection = new RASPPPIP();
    IntByReference lpcb = new IntByReference(pppIpProjection.size());
    pppIpProjection.write();
    int err = Rasapi32.INSTANCE.RasGetProjectionInfo(hrasConn, RASP_PppIp, pppIpProjection.getPointer(), lpcb);
    if (err != WinError.ERROR_SUCCESS)
        throw new Ras32Exception(err);
    pppIpProjection.read();
    return pppIpProjection;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) RASPPPIP(com.sun.jna.platform.win32.WinRas.RASPPPIP)

Example 82 with IntByReference

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

the class Secur32Util method getUserNameEx.

/**
	 * Retrieves the name of the user or other security principal associated 
	 * with the calling thread.
	 * 
	 * @param format User name format.
	 * @return User name in a given format.
	 */
public static String getUserNameEx(int format) {
    char[] buffer = new char[128];
    IntByReference len = new IntByReference(buffer.length);
    boolean result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
    if (!result) {
        int rc = Kernel32.INSTANCE.GetLastError();
        switch(rc) {
            case W32Errors.ERROR_MORE_DATA:
                buffer = new char[len.getValue() + 1];
                break;
            default:
                throw new Win32Exception(Native.getLastError());
        }
        result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
    }
    if (!result) {
        throw new Win32Exception(Native.getLastError());
    }
    return Native.toString(buffer);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference)

Example 83 with IntByReference

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

the class User32Util method GetRawInputDeviceList.

public static final List<RAWINPUTDEVICELIST> GetRawInputDeviceList() {
    IntByReference puiNumDevices = new IntByReference(0);
    RAWINPUTDEVICELIST placeholder = new RAWINPUTDEVICELIST();
    int cbSize = placeholder.sizeof();
    // first call is with NULL so we query the expected number of devices
    int returnValue = User32.INSTANCE.GetRawInputDeviceList(null, puiNumDevices, cbSize);
    if (returnValue != 0) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    int deviceCount = puiNumDevices.getValue();
    RAWINPUTDEVICELIST[] records = (RAWINPUTDEVICELIST[]) placeholder.toArray(deviceCount);
    returnValue = User32.INSTANCE.GetRawInputDeviceList(records, puiNumDevices, cbSize);
    if (returnValue == (-1)) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    if (returnValue != records.length) {
        throw new IllegalStateException("Mismatched allocated (" + records.length + ") vs. received devices count (" + returnValue + ")");
    }
    return Arrays.asList(records);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) RAWINPUTDEVICELIST(com.sun.jna.platform.win32.WinUser.RAWINPUTDEVICELIST)

Example 84 with IntByReference

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

the class Rasapi32Util method getRasConnection.

/**
	 * Return a RAS connection by name
	 * @param connName the connection name
	 * @return the RAS connection structure
	 * @throws Ras32Exception errors
	 */
public static HANDLE getRasConnection(String connName) throws Ras32Exception {
    // size the array needed
    IntByReference lpcb = new IntByReference(0);
    IntByReference lpcConnections = new IntByReference();
    int err = Rasapi32.INSTANCE.RasEnumConnections(null, lpcb, lpcConnections);
    if (err != WinError.ERROR_SUCCESS && err != WinRas.ERROR_BUFFER_TOO_SMALL)
        throw new Ras32Exception(err);
    if (lpcb.getValue() == 0)
        return null;
    // get the connections
    RASCONN[] connections = new RASCONN[lpcConnections.getValue()];
    for (int i = 0; i < lpcConnections.getValue(); i++) connections[i] = new RASCONN();
    lpcb = new IntByReference(connections[0].dwSize * lpcConnections.getValue());
    err = Rasapi32.INSTANCE.RasEnumConnections(connections, lpcb, lpcConnections);
    if (err != WinError.ERROR_SUCCESS)
        throw new Ras32Exception(err);
    // find connection
    for (int i = 0; i < lpcConnections.getValue(); i++) {
        if (new String(connections[i].szEntryName).equals(connName))
            return connections[i].hrasconn;
    }
    return null;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) RASCONN(com.sun.jna.platform.win32.WinRas.RASCONN)

Example 85 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jnanomsg by niwinz.

the class Nanomsg method getSymbols.

private static final Map<String, Integer> getSymbols() {
    HashMap<String, Integer> result = new HashMap<String, Integer>();
    int index = 0;
    while (true) {
        IntByReference valueRef = new IntByReference();
        Pointer ptr = NativeLibrary.nn_symbol(index, valueRef);
        if (ptr == null) {
            break;
        }
        result.put(ptr.getString(0), valueRef.getValue());
        index += 1;
    }
    return result;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HashMap(java.util.HashMap) 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