Results 1 to 2 of 2
  1. #1
    dkas is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default Using jna for SendMessage Windows call

    Hi,
    I am trying to use jna for making a win32 API call. I need to SendMessage to a window.

    I have a long handle and I am trying to pass it as follows but SendMessage is not returning the correct value. Can someone throw some light on what is wrong with the way I am passing the handle ?




    System.out.println("Process ID: " + activeWindow1.getPid());

    long handle1 = activeWindow1.getHandle(); // This prints 263948
    NativeLong nl = new NativeLong(handle1);

    User32 lib = User32.INSTANCE;
    NativeLongByReference nlbr = new NativeLongByReference(nl);

    long ret1 = lib.SendMessageA(new LongByReference(handle1).getPointer().getPointer(0 ), 32771, 0, 0);

    System.out.println("Return value=" + ret1); // This returns 8975925931411506151, expected is 999
    long ret2 = lib.SendMessageA(nlbr.getPointer().getPointer(0), 32771, 0, 0);
    System.out.println("Return value=" + ret2); //This call also returns 8975925931411506151, expected is 999

    }


    // This is the standard, stable way of mapping, which supports extensive
    // customization and mapping of Java to native types.
    public interface User32 extends com.sun.jna.platform.win32.User32 {
    User32 INSTANCE = (User32)
    Native.loadLibrary("user32",User32.class);
    long SendMessageA(Pointer hWnd,int msg,int num1,int num2);
    long SendMessageA(PointerType hWnd,int msg,int num1,int num2);

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    cross post

    https://jna.dev.java.net/servlets/Re...ers&msgNo=4436

    It's bad form to post the same question on multiple forums, but I understand why you are doing it since you are not getting any help. From a cursory look at the User32.SendMessageA, it is supposed to return a handle. Handles can change from run to run, so I'm not sure why you expect it to be 999.

Similar Threads

  1. call by value and call by reference in java
    By sandeepsai39 in forum New To Java
    Replies: 7
    Last Post: 08-12-2010, 11:03 AM
  2. small windows
    By ghostofdarling in forum Java Applets
    Replies: 1
    Last Post: 04-17-2010, 08:55 AM
  3. Under Windows OS, how to call *.EXE produced in Linux OS?
    By tony_lincoln in forum Advanced Java
    Replies: 9
    Last Post: 03-26-2010, 06:08 PM
  4. how to do a Windows Explorer
    By Panchitopro in forum AWT / Swing
    Replies: 8
    Last Post: 05-08-2008, 03:31 AM
  5. swt for windows
    By Gajesh Tripathi in forum SWT / JFace
    Replies: 2
    Last Post: 10-18-2007, 06:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •