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