Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing JNA to get/set application identifier
    primarykey
    data
    text
    <p>Following up on <a href="https://stackoverflow.com/questions/1834599/pinning-a-java-application-to-the-windows-7-taskbar">my previous question concerning the Windows 7 taskbar</a>, I would like to diagnose why Windows isn't acknowledging that my application is independent of <code>javaw.exe</code>. I presently have the following JNA code to obtain the <a href="http://msdn.microsoft.com/en-us/library/dd378459%28VS.85%29.aspx" rel="noreferrer"><code>AppUserModelID</code></a>:</p> <pre><code>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() + "."); } } } </code></pre> <p>The output of the application is seemingly gibberish:</p> <pre><code>1: ‹ÿU‹ìƒìL¡¬Ÿv3ʼnEüSV‹uƒ&amp; 2: ‹ÿU‹ìƒìL¡¬Ÿv3ʼnEüSV‹uƒ&amp; 3: ????????????????P??????????? </code></pre> <p>Being aware of the fact that the output may be UTF-16, in (3) I attempted to convert a byte array from UTF-16. In all honesty I don't know if my approach here is right as (a) I don't know the size of a <code>PWSTR</code> and (b) I don't know if <a href="http://msdn.microsoft.com/en-us/library/dd378419%28VS.85%29.aspx" rel="noreferrer"><code>GetCurrentProcessExplicitAppUserModelID</code></a> is indeed returning a byte array or string.</p> <p>I'm aware that JSmooth will run the GUI process in a wrapper which simulates this effect. Launch4j claims to do the same, but doesn't appear to work. I am looking to have the <code>AppUserModelID</code> set <em>regardless of the Java wrapper</em>.</p> <p>What is going wrong here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload