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);