SendInput BlitzMax conversion.

BlitzMax Forums/BlitzMax Programming/SendInput BlitzMax conversion.

Thareh(Posted 2010) [#1]
Hi!
I'm trying to use SendInput to generate some mouse and keyboard strokes.
I've had success with the mouse part of the function, but I can't get the keyboard part to work.
I'm thinking it has to do with the data types that BlizMax can't handle.

I've translated this:


Into this:


Is this correct?


_JIM(Posted 2010) [#2]
I believe WORD is the equivalent of Short in bmax as the DWORD is a doubleword which is the size of an Int which is 4 bytes.


Thareh(Posted 2010) [#3]
I think I found the problem!



If you add the fields sizes together manually, you get the right size.
But if you use SizeOf( KBInput ) you get 4 bytes more than you should?


Brucey(Posted 2010) [#4]
But if you use SizeOf( KBInput ) you get 4 bytes more than you should

Either because of the 4 bytes for the type itself, or because dwExtraInfo is aligned to 8 bytes.


Brucey(Posted 2010) [#5]
Anyway. Long is not LONG. LONG is Int.


Thareh(Posted 2010) [#6]
What does aligned to 8 bytes mean?



If I change two of the fields to Shorts the SizeOf( KBInput ) goes down by 8 instead of 4?


Floyd(Posted 2010) [#7]
Aligned to 8 bytes means padded with unused bytes, if necessary, so the address is a multiple of 8. Your first example with 5 Ints has 20 bytes before the last field. Thus 4 unused bytes are added to make this 24. The second example, with two Shorts, gives an offset of 16, already a multiple of 8, so no padding is needed.

I believe the size of word, dword and long are 2,4,4 so the corresponding BlitzMax datatypes would be Short, Int, Int. A BlitzMax Long is 8 bytes.


Thareh(Posted 2010) [#8]
Oh okey :O :S
Is there any way to get the actual size then? The size without padding etc.


Floyd(Posted 2010) [#9]
The actual size? That would be the size with padding.

In all cases I have checked BlitzMax uses the same padding/alignment as MinGW so this shouldn't be a problem.

The original struct doesn't have or need any padding. The data sizes are 2,2,4,4,4 and everything is already on a 2-byte or 4-byte boundary. If you changed the first DWORD to a WORD the size would not decrease by 2 bytes as you might expect since 2 bytes of padding would now be added in order to align the next DWORD.