Java等效的MOUSE_INPUT_DATA

时间:2016-01-11 07:27:05

标签: java c++ driver

我正在尝试将C ++ MOUSE_INPUT_DATA结构转换为JNA。

typedef struct _MOUSE_INPUT_DATA {
  USHORT UnitId;
  USHORT Flags;
  union {
    ULONG  Buttons;
    struct {
      USHORT ButtonFlags;
      USHORT ButtonData;
    };
  };
  ULONG  RawButtons;
  LONG   LastX;
  LONG   LastY;
  ULONG  ExtraInformation;
} MOUSE_INPUT_DATA, *PMOUSE_INPUT_DATA;

我最好的猜测

public static class _MOUSE_INPUT_DATA extends Structure {

        public static class ByReference extends _MOUSE_INPUT_DATA implements Structure.ByReference {
            public ByReference() {
            }

            public ByReference(Pointer memory) {
                super(memory);
            }
        }

        public _MOUSE_INPUT_DATA() {
        }

        public _MOUSE_INPUT_DATA(Pointer memory) {
            super(memory);
            read();
        }

        public WinDef.WORD unitId;
        public WinDef.WORD flags;
        public MOUSE_INPUT_DATA_UNION_STRUCT union = new MOUSE_INPUT_DATA_UNION_STRUCT();
        public WinDef.ULONG rawButtons;
        public WinDef.LONG lastX;
        public WinDef.LONG lastY;
        public BaseTSD.ULONG_PTR extraInformation;

        protected List getFieldOrder() {
            return Arrays.asList(new String[]{"unitId", "flags", "union", "rawButtons", "lastX", "lastY", "extraInformation"});
        }

    }

    public static class MOUSE_INPUT_DATA_UNION_STRUCT extends Structure {

        public static class ByReference extends MOUSE_INPUT_DATA_UNION_STRUCT implements Structure.ByReference {
            public ByReference() {
            }

            public ByReference(Pointer memory) {
                super(memory);
            }
        }

        public MOUSE_INPUT_DATA_UNION_STRUCT() {
        }

        public MOUSE_INPUT_DATA_UNION_STRUCT(Pointer memory) {
            super(memory);
            read();
        }

        public _MOUSE_INPUT_DATA_UNION_STUCT_DETAIL union = new _MOUSE_INPUT_DATA_UNION_STUCT_DETAIL();

        protected List getFieldOrder() {
            return Arrays.asList(new String[]{"union"});
        }

        public static class _MOUSE_INPUT_DATA_UNION_STUCT_DETAIL extends Union {

            public _MOUSE_INPUT_DATA_UNION_STUCT_DETAIL() {
            }

            public _MOUSE_INPUT_DATA_UNION_STUCT_DETAIL(Pointer memory) {
                super(memory);
                read();
            }

            public WinDef.ULONG buttons;
            public WinDef.ULONG flagsAndData;
        }
    }

我正在使用它在自定义驱动程序中传递此结构。我有一个Delphi应用程序,可以正常使用驱动程序和此结构,但JAVA不是。

任何人都可以对我出错的地方给出一些提示吗?

1 个答案:

答案 0 :(得分:0)

Ок。我找到了中间结果。

public class MOUSE_INPUT_DATA extends Structure {

    public static class ByReference extends MOUSE_INPUT_DATA implements Structure.ByReference {
        public ByReference() {
        }

        public ByReference(Pointer memory) {
            super(memory);
        }
    }

    public MOUSE_INPUT_DATA() {
    }

    public MOUSE_INPUT_DATA(Pointer memory) {
        super(memory);
        read();
    }

    public WinDef.WORD UnitId;
    public WinDef.WORD Flags;
    public WinDef.DWORD Buttons;
    public WinDef.DWORD RawButtons;
    public WinDef.DWORD LastX;
    public WinDef.DWORD LastY;
    public WinDef.DWORD ExtraInformation;

    protected List getFieldOrder() {
        return Arrays.asList(new String[]{"UnitId", "Flags", "Buttons", "RawButtons", "LastX", "LastY", "ExtraInformation"});
    }

}