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