winapi - tagRAWMOUSE Structure Issues -
i have set raw input trigger wm_input on message window. have set input mouse. succesfully getting messages , calling getrawinputdata().
i followed documentation letter being bit silly.
the docs struct receive:
so doing ctypes why im getting this.
when mouse wheel this:
tagrawmouse(0, 0, 1024, 0, 0, 0, 0) and when mouse wheel down exact same thing:
tagrawmouse(0, 0, 1024, 0, 0, 0, 0) as guide, when mouse move mouse gets this:
tagrawmouse(0, 0, 0, 0, 0, 1, 0) i set struct union 2 ushort ctypes not support union:
this.rawmouse = ctypes.structtype('tagrawmouse', [ { usflags: this.ushort }, { usbuttonflags: this.ushort }, { usbuttondata: this.ushort }, { ulrawbuttons: this.ulong }, { llastx: this.long }, { llasty: this.long }, { ulextrainformation: this.ulong } ]); does see wrong?
let's re-cap c++ definition of struct since important:
typedef struct tagrawmouse { ushort usflags; union { ulong ulbuttons; struct { ushort usbuttonflags; ushort usbuttondata; }; }; ulong ulrawbuttons; long llastx; long llasty; ulong ulextrainformation; } rawmouse, *prawmouse, *lprawmouse; the union messing alignment. union needs aligned of members aligned. because union has ulong member, namely ulbuttons, union's alignment 4 bytes. therefore union has placed @ offset multiple of 4. in case places @ offset 4. , there 2 bytes of padding after usflags.
in ctypes struct, 2 ushort members of union overlay ulong, namely usbuttonflags , usbuttondata have alignment 2. therefore placed @ offsets 2 , 4. , padding has been lost in translation.
this sort of thing common, , 1 of first things check when translating struct. dig out c++ compiler , emit size of struct, , offsets members. compare same information translation. if don't match, work out why.
you have couple of ways fix it:
- replace
usbuttonflags,usbuttondataulong, use bitwise operations pick out 2ushortvalues. - add dummy padding
ushortahead ofusbuttonflags.
Comments
Post a Comment