I'm translating some WinAPI structs so I can make use of the Raw Input API exposed by user32.

I'm translating some WinAPI structs so I can make use of the Raw Input API exposed by user32.dll. Most of them are straight forward but a few have unions. I've never attempted to translate structs to records before and I'm just need some confirmation.

I have the following two structs:

typedef struct tagRAWMOUSE {
  USHORT usFlags;
  union {
    ULONG  ulButtons;
    struct {
      USHORT usButtonFlags;
      USHORT usButtonData;
    };
  };
  ULONG  ulRawButtons;
  LONG   lLastX;
  LONG   lLastY;
  ULONG  ulExtraInformation;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;

typedef struct tagRAWINPUT {
  RAWINPUTHEADER header;
  union {
    RAWMOUSE    mouse;
    RAWKEYBOARD keyboard;
    RAWHID      hid;
  } data;
} RAWINPUT, *PRAWINPUT, *LPRAWINPUT;

And here are my attempts to translate:

type
  RAWMOUSE = record
    usFlags: USHORT;
    case Boolean of
    False: (ulButtons: ULONG);
    True: (usButtonFlags: USHORT;
           usButtonData: USHORT;
           ulRawButtons: ULONG;
           lLastX: LongInt;
           lLastY: LongInt;
           ulExtraInformation: ULONG);
  end;
  PRAWMOUSE = ^RAWMOUSE;
  LPRAWMOUSE = PRAWMOUSE;

type
  RAWINPUT = record
    header: RAWINPUTHEADER;
    case Integer of
    0: (mouse: RAWMOUSE);
    1: (keyboard: RAWKEYBOARD);
    2: (hid: RAWHID);
  end;
PRAWINPUT = ^RAWINPUT;
LPRAWINPUT = PRAWINPUT;

How close to the mark did I get?

Comments