title: Converting String to Pointer for JNA
body: <p>I'm trying to use JNA to query the effective permissions for a file in Windows.  Eventually, I plan on using the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa446637%28v=vs.85%29.aspx" rel="nofollow">GetEffectiveRightsFromAcl function</a>, but to do so, I need to provide a pointer to a populated <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa379636%28v=vs.85%29.aspx" rel="nofollow">TRUSTEE structure</a>.  The JNA Platform (platform.jar) doesn't appear define this struct, so I'm trying to define it myself instead.  Here's what I have so far:</p>
  
  <pre><code>public static class TRUSTEE extends Structure {
      public TRUSTEE() {
          super();
      }
      public TRUSTEE(Pointer p) {
          super(p);
          read();
      }
  
      public Pointer pMultipleTrustee;
      public int MultipleTrusteeOperation;
      public int TrusteeForm;
      public int TrusteeType;
      public Pointer ptstrName;
  }
  </code></pre>
  
  <p>I'm trying to populate the structure like this:</p>
  
  <pre><code>private TRUSTEE createTrusteeForCurrentUser() {
      TRUSTEE result = new TRUSTEE();
      result.TrusteeForm = TRUSTEE_FORM.TRUSTEE_IS_NAME;
      result.TrusteeType = TRUSTEE_TYPE.TRUSTEE_IS_USER;
  
      String strName = "CURRENT_USER";
      // How can I set result.ptstrName using strName?
  }
  </code></pre>
  
  <p><a href="http://groups.google.com/group/jna-users/browse_thread/thread/48ab9f7c642c1eb2/058d75cf3fc330a2" rel="nofollow">This Google Groups thread</a> recommends using <code>String</code> fields in structures when a <code>char *</code> is called for.  However, I don't think this is appropriate in my situation, considering the <code>ptstrName</code> field is allowed to point to different types of things, depending on the value of <code>TrusteeForm</code>.  So, I think I somehow need to convert from <code>String</code> to <code>Pointer</code> instead.  I found the <a href="http://jna.java.net/javadoc/com/sun/jna/NativeString.html" rel="nofollow">NativeString</a> class in JNA, which would work, except it's a package-private class.</p>
  
  <p>What's the recommended way to convert a Java <code>String</code> to a native format and obtain a <code>Pointer</code> to it?  Am I even using the right data type for the <code>TRUSTEE</code> struct?  I'm somewhat new to JNA, so please excuse me if I'm missing something obvious.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I found a solution to my problem, but if anyone has a better solution I'd still like to hear it.</p>