Jump to content

Structure in AutoIt


Go to solution Solved by Mat,

Recommended Posts

Try this:

$tStruct_Test = DllStructCreate("uint anUINT;uint anotherUINT")

DllStructSetData($tStruct_Test, "anUINT", -100) ;either
$tStruct_Test.anotherUINT = 100 ;or

MsgBox(0, "Test", DllStructGetData($tStruct_Test,  "anUINT") & @CRLF & $tStruct_Test.anotherUINT)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Solution

There is no way to have bit fields in AutoIt. Instead you'll have to use bitwise operators to extract required bits. It's not too tricky to do, but unfortunately it means you can't have the nice syntax we have use for structs at the moment.

For everyone else, the struct in the first post is actually only 1 UINT long, and the two fields are just single bits. That's a very different structure to what you have posted UEZ.

Link to comment
Share on other sites

EndlessLove, You can also use an array of arrays, which is much easier to use than DllStructCreate and just as fast.

Link to comment
Share on other sites

Sorry, but my C/C++ knowledge is very limited...

Bit fields are hardly ever used in the winapi (in fact I can't think of any structures where they are used), and I have never come across them in practice either. I only know of them because I read the C standard and stumbled across them whilst looking for other information. That's probably why they've never been asked for in AutoIt before as well.

Mat

Link to comment
Share on other sites

Thanks everyone for replying.

Try this:

$tStruct_Test = DllStructCreate("uint anUINT;uint anotherUINT")

DllStructSetData($tStruct_Test, "anUINT", -100) ;either
$tStruct_Test.anotherUINT = 100 ;or

MsgBox(0, "Test", DllStructGetData($tStruct_Test, "anUINT") & @CRLF & $tStruct_Test.anotherUINT)

Br,

UEZ

 

Thank you, now I know another way to get/set data of an element of a structure :)

Bit fields are hardly ever used in the winapi (in fact I can't think of any structures where they are used), and I have never come across them in practice either. I only know of them because I read the C standard and stumbled across them whilst looking for other information. That's probably why they've never been asked for in AutoIt before as well.

Mat

 

I use WM_COPYDATA to send a packet buffer from C++ DLL to AutoIt, so I want to create a structure (IP Header & TCP Header structure) in AutoIt which points to the packet buffer so that I can easily manage the data of the IP/TCP Header structure.

If AutoIt structures can't have bit-fields then I think I will use bitwise operator like you suggest.

Thank you :)

.

Edited by EndlessLove
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...