Jump to content

DllStructGetSize byte size


Go to solution Solved by stormbreaker,

Recommended Posts

Hi,

I don't understand how the size of the structure works.

 

I know that an int has a size of 4 bytes, if I get the size of the struct then I have 4 bytes;

a byte has as size of 1 byte, if I get the size of the struct then I have 1 byte.

 

Until here everything seems fine, unless I make a structure with the two elements, the size is 8 bytes; 4+1=5 and not 8.

 

Here is the example :

#include <Constants.au3>
 
Local Const $tagSTRUCT1 = "struct;int var1;endstruct"
Local $tSTRUCT1 = DllStructCreate($tagSTRUCT1)
 
MsgBox($MB_SYSTEMMODAL, "", "Struct1 Size: " & DllStructGetSize($tSTRUCT1))
 
 
Local Const $tagSTRUCT2 = "struct;byte var2;endstruct"
Local $tSTRUCT2 = DllStructCreate($tagSTRUCT2)
 
MsgBox($MB_SYSTEMMODAL, "", "Struct2 Size: " & DllStructGetSize($tSTRUCT2))
 
 
Local Const $tagSTRUCT3 = "struct;int var1;byte var2;endstruct"
Local $tSTRUCT3 = DllStructCreate($tagSTRUCT3)
 
MsgBox($MB_SYSTEMMODAL, "", "Struct3 Size: " & DllStructGetSize($tSTRUCT3))
Thanks for anyhelp :)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

  • Solution

Firefox, we need to use align here. Read help file for DllStructCreate() function

FROM help file:

DllStructCreate("short;int") ; structure is 8 bytes, the "int" is at offset 4
DllStructCreate("align 2;short;int") ; structure is 6 bytes, the "int" is at offset 2

Regards,

MKISH

Edited by MKISH

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...