Search in sources :

Example 1 with RASCONN

use of com.sun.jna.platform.win32.WinRas.RASCONN 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)

Aggregations

RASCONN (com.sun.jna.platform.win32.WinRas.RASCONN)1 IntByReference (com.sun.jna.ptr.IntByReference)1