title: JNA call PostMessage ~ passing String "Environment"
body: <p><a href="http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849/Setting-a-System-Environment-Variable.htm" rel="nofollow">http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849/Setting-a-System-Environment-Variable.htm</a></p>
  
  <p>SendMessage( HWND_BROADCAST , WM_SETTINGCHANGE , 0 , (LPARAM) "Environment" );</p>
  
  <p>JNA and windows xp: call to notify that Environment has been changed</p>
  
  <p>see link: twall.github.com/jna/3.5.1/javadoc/</p>
  
  <p>see link: twall.github.com/jna/3.5.1/javadoc/com/sun/jna/platform/win32/User32.html</p>
  
  <p>PostMessage(WinDef.HWND hWnd, int msg, WinDef.WPARAM wParam, WinDef.LPARAM lParam)</p>
  
  <p>This function places a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.</p>
  
  <pre><code>import com.sun.jna.*;
  import com.sun.jna.win32.*;
  import com.sun.jna.platform.win32.*;
  import com.sun.jna.ptr.*;
  
  public class MainJNA {
  
  public static void main (String [] args){
  
  String  myString = "Environment";
  Pointer myPointer = new Memory(myString.length()+1);
      myPointer.setString(0,myString);
  
  Pointer HWND_BROADCAST = new Pointer(0xFFFF);
  
  int           msg    = 0x001A; // WM_SETTINGCHANGE = WM_WININICHANGE = 0x001A
  WinDef.HWND   hWnd   = new WinDef.HWND( HWND_BROADCAST );
  WinDef.WPARAM wParam = new WinDef.WPARAM(0);
  WinDef.LPARAM lParam = new WinDef.LPARAM( myPointer.getLong(0) );
  // Exception in thread "main" java.lang.IllegalArgumentException:
  // Argument value 0x6d6e6f7269766e45 exceeds native capacity (4 bytes)
  // mask=0xffffffff00000000
  
  User32 user32 = (User32) Native.loadLibrary(
  "user32" , User32.class , W32APIOptions.DEFAULT_OPTIONS );
  user32.PostMessage( hWnd , msg , wParam , lParam );
  
  }
  
  } // end of class MainJNA
  </code></pre>
  
  <p><strong>How to pass String parameter "Environment" to user32.PostMessage ???</strong></p>
  
  <p>And not to get <strong>Exception in thread "main" java.lang.IllegalArgumentException: Argument value 0x6d6e6f7269766e45 exceeds native capacity (4 bytes) mask=0xffffffff00000000</strong></p>
  
  <p>Thx</p>