Why does my call to winapi GetWindowPlacement fail (using JNA)?

限于喜欢 提交于 2019-12-08 07:24:33

问题


These are the winapi methods

BOOL WINAPI SetWindowPlacement(
  _In_       HWND            hWnd,
  _In_ const WINDOWPLACEMENT *lpwndpl
);
typedef struct tagWINDOWPLACEMENT {
  UINT  length;
  UINT  flags;
  UINT  showCmd;
  POINT ptMinPosition;
  POINT ptMaxPosition;
  RECT  rcNormalPosition;
} WINDOWPLACEMENT, *PWINDOWPLACEMENT, *LPWINDOWPLACEMENT;

My Java code:-

class WINDOWPLACEMENT{
   public int length;
   public int flags;
   public int showCmd;
   public POINT    ptMinPosition;
   public POINT    ptMaxPosition;
   public RECT     rcNormalPosition;
}
WINDOWPLACEMENT wind = new WINDOWPLACEMENT();
User32Extra.INSTANCE.GetWindowPlacement(hwndLSM, wind);

The error is

java.lang.IllegalArgumentException: Unsupported argument type jna.extra.WINDOWPLACEMENT at parameter 1 of function GetWindowPlacement

How to use GetWindowPlacement/SetWindowPlacement with JNA?


回答1:


java.extra.WINDOWPLACEMENT must extend com.sun.jna.Structure and properly implement getFieldOrder().

EDIT

Setting length in the constructor, and getFieldOrder() definition:

public class WINDOWPLACEMENT extends Structure {
    public WINDOWPLACEMENT() {
        this.length = size();
    }
    public List getFieldOrder() {
        return Arrays.asList("length", "flags", "showCmd", "ptMinPosition", "ptMaxPosition", "rcNormalPosition");
    }
    // ...
}


来源:https://stackoverflow.com/questions/31312793/why-does-my-call-to-winapi-getwindowplacement-fail-using-jna

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!