Usando o JNA para obter / definir o identificador de aplicativo
Seguindo em frenteminha pergunta anterior sobre a barra de tarefas do Windows 7, Gostaria de diagnosticar porque o Windows não está reconhecendo que meu aplicativo é independentejavaw.exe
. Eu atualmente tenho o seguinte código JNA para obter oAppUserModelID
:
public class AppIdTest {
public static void main(String[] args) {
NativeLibrary lib;
try {
lib = NativeLibrary.getInstance("shell32");
} catch (Error e) {
System.err.println("Could not load Shell32 library.");
return;
}
Object[] functionArgs = new Object[1];
String functionName = null;
Function function;
try {
functionArgs[0] = new String("Vendor.MyJavaApplication")
.getBytes("UTF-16");
functionName = "GetCurrentProcessExplicitAppUserModelID";
function = lib.getFunction(functionName);
// Output the current AppId
System.out.println("1: " + function.getString(0));
functionName = "SetCurrentProcessExplicitAppUserModelID";
function = lib.getFunction(functionName);
// Set the new AppId
int ret = function.invokeInt(functionArgs);
if (ret != 0) {
Logger.out.error(function.getName() + " returned error code "
+ ret + ".");
}
functionName = "GetCurrentProcessExplicitAppUserModelID";
function = lib.getFunction(functionName);
// Output the current AppId
System.out.println("2: " + function.getString(0));
// Output the current AppID, converted from UTF-16
System.out.println("3: "
+ new String(function.getByteArray(0, 255), "UTF-16"));
} catch (UnsupportedEncodingException e) {
System.err.println("System does not support UTF-16 encoding.");
} catch (UnsatisfiedLinkError e) {
System.err.println(functionName + " was not found in "
+ lib.getFile().getName() + ".");
}
}
}
A saída do aplicativo é aparentemente sem sentido:
1: ‹ÿU‹ìƒìL¡¬Ÿv3ʼnEüSV‹uƒ&
2: ‹ÿU‹ìƒìL¡¬Ÿv3ʼnEüSV‹uƒ&
3: ????????????????P???????????
Estando ciente do fato de que a saída pode ser UTF-16, em (3) eu tentei converter uma matriz de bytes de UTF-16. Com toda a honestidade, não sei se a minha abordagem aqui está certa, pois (a) não sei o tamanho de umaPWSTR
e (b) não sei seGetCurrentProcessExplicitAppUserModelID
está de fato retornando uma matriz de bytes ou uma string.
Estou ciente de que o JSmooth executará o processo da GUI em um wrapper que simula esse efeito. Launch4j afirma fazer o mesmo, mas não parece funcionar. Eu estou olhando para ter oAppUserModelID
conjuntoindependentemente do wrapper Java.
o que há de errado aqui?