Jump to content

Recommended Posts

Posted

Hello there, I'm new to AutoIt forum. Today, I want to ask a question about Structure in AutoIt

Is there any way to create structure elements with bitfields?

Like in C/C++:

struct
{
  unsigned int anUINT: 1;
  unsigned int anotherUINT : 1;
} test;

Thanks.

Posted

DllStructCreate()  ?

And welcome to the Forum. :thumbsup:

Hi Exit, thanks for your reply.

I tried that, but I don't know how to set bit-fields for each element in the structure : .

Sorry for my bad English.

Posted (edited)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

  • Solution
Posted

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.

Posted

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

Posted

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

Posted (edited)

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

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
×
×
  • Create New...