Windows 7 のタスクバーに関する以前の質問に続き、アプリケーションが に依存していないことを Windows が認識しない理由を診断したいと思いますjavaw.exe
。現在、次のJNAコードを取得して取得していAppUserModelID
ます:
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() + ".");
}
}
}
アプリケーションの出力は一見意味不明です。
1: ‹ÿU‹ìƒìL¡¬Ÿv3ʼnEüSV‹uƒ&
2: ‹ÿU‹ìƒìL¡¬Ÿv3ʼnEüSV‹uƒ&
3: ????????????????P???????????
出力がUTF-16である可能性があることを認識して、(3)バイト配列をUTF-16から変換してみました。PWSTR
正直なところ、(a) a のサイズがわからず、(b)GetCurrentProcessExplicitAppUserModelID
が実際にバイト配列または文字列を返すかどうかわからないため、ここでの私のアプローチが正しいかどうかはわかりません。
JSmooth は、この効果をシミュレートするラッパーで GUI プロセスを実行することを認識しています。Launch4j は同じことを行うと主張していますが、機能していないようです。Javaラッパーに関係なくAppUserModelID
、セットを探しています。
ここで何がうまくいかないのですか?