use of com.sun.jna.platform.win32.WinDef.BYTE in project jna by java-native-access.
the class WTypesTest method testBSTRBasic.
public void testBSTRBasic() {
String demoString = "inputÖäÜ?!";
// Allocation via system and the "correct" way
BSTR sysAllocated = OleAuto.INSTANCE.SysAllocString(demoString);
// Java based allocation - not suitable if passed via automation
BSTR javaAllocated = new BSTR(demoString);
// Ensure encoding roundtripping works
assertEquals(demoString, sysAllocated.getValue());
assertEquals(demoString, javaAllocated.getValue());
// BSTR is encoded as UTF-16/UCS2, so byte length is 2 * char count
assertEquals(demoString.length(), OleAuto.INSTANCE.SysStringLen(sysAllocated));
assertEquals(demoString.length(), OleAuto.INSTANCE.SysStringLen(javaAllocated));
assertEquals(2 * demoString.length(), OleAuto.INSTANCE.SysStringByteLen(sysAllocated));
assertEquals(2 * demoString.length(), OleAuto.INSTANCE.SysStringByteLen(javaAllocated));
// The BSTR Pointer points 4 bytes into the data itself (beginning of data
// string, the 4 preceding bytes code the string length (in bytes)
assertEquals(2 * demoString.length(), sysAllocated.getPointer().getInt(-4));
assertEquals(2 * demoString.length(), javaAllocated.getPointer().getInt(-4));
OleAuto.INSTANCE.SysFreeString(sysAllocated);
// javaAllocated is allocated via Memory and will be freeed by the
// garbadge collector automaticly
}
use of com.sun.jna.platform.win32.WinDef.BYTE in project processing by processing.
the class WindowsRegistry method getStringValue.
/**
* Read a String value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @throws java.io.UnsupportedEncodingException on error
* @return String or null
*/
public static String getStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) throws UnsupportedEncodingException {
//Advapi32 advapi32;
//IntByReference pType, lpcbData;
byte[] lpData = new byte[1];
//int handle = 0;
Advapi32 advapi32 = Advapi32.INSTANCE;
IntByReference pType = new IntByReference();
IntByReference lpcbData = new IntByReference();
HKEY handle = openKey(rootKey, subKeyName, WinNT.KEY_READ);
String ret = null;
//if (handle != 0) {
if (handle != null) {
//if (advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WinError.ERROR_MORE_DATA) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) == WinError.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
//if (advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WinError.ERROR_SUCCESS) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) == WinError.ERROR_SUCCESS) {
ret = convertBufferToString(lpData);
}
}
advapi32.RegCloseKey(handle);
}
return ret;
}
use of com.sun.jna.platform.win32.WinDef.BYTE in project processing by processing.
the class WindowsRegistry method getValues.
/**
* Get all values under a key.
*
* @param rootKey root key
* @param key jey name
* @throws java.io.UnsupportedEncodingException on error
* @return TreeMap with name and value pairs
*/
public static TreeMap<String, Object> getValues(REGISTRY_ROOT_KEY rootKey, String key) throws UnsupportedEncodingException {
//Advapi32 advapi32;
//int handle = 0, dwIndex, result = 0;
//char[] lpValueName;
//byte[] lpData;
//IntByReference lpcchValueName, lpType, lpcbData;
//String name;
TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
Advapi32 advapi32 = Advapi32.INSTANCE;
HKEY handle = openKey(rootKey, key, WinNT.KEY_READ);
char[] lpValueName = new char[16384];
IntByReference lpcchValueName = new IntByReference(16384);
IntByReference lpType = new IntByReference();
byte[] lpData = new byte[1];
IntByReference lpcbData = new IntByReference();
//if(handle != 0) {
if (handle != null) {
int dwIndex = 0;
int result = 0;
String name;
do {
lpcbData.setValue(0);
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData);
if (result == WinError.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
lpcchValueName = new IntByReference(16384);
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData);
if (result == WinError.ERROR_SUCCESS) {
name = new String(lpValueName, 0, lpcchValueName.getValue());
switch(lpType.getValue()) {
case WinNT.REG_SZ:
values.put(name, convertBufferToString(lpData));
break;
case WinNT.REG_DWORD:
values.put(name, convertBufferToInt(lpData));
break;
default:
break;
}
}
}
dwIndex++;
} while (result == WinError.ERROR_SUCCESS);
advapi32.RegCloseKey(handle);
}
return values;
}
Aggregations