EndlessLove Posted December 28, 2014 Share Posted December 28, 2014 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. Link to comment Share on other sites More sharing options...
Exit Posted December 28, 2014 Share Posted December 28, 2014 (edited) DllStructCreate() ? And welcome to the Forum. Edited December 28, 2014 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
EndlessLove Posted December 28, 2014 Author Share Posted December 28, 2014 DllStructCreate() ? And welcome to the Forum. 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. Link to comment Share on other sites More sharing options...
UEZ Posted December 28, 2014 Share Posted December 28, 2014 (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 December 28, 2014 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 More sharing options...
Solution Mat Posted December 28, 2014 Solution Share Posted December 28, 2014 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. AutoIt Project Listing Link to comment Share on other sites More sharing options...
UEZ Posted December 28, 2014 Share Posted December 28, 2014 Sorry, but my C/C++ knowledge is very limited... Br, 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 More sharing options...
LarsJ Posted December 28, 2014 Share Posted December 28, 2014 EndlessLove, You can also use an array of arrays, which is much easier to use than DllStructCreate and just as fast. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Mat Posted December 28, 2014 Share Posted December 28, 2014 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 AutoIt Project Listing Link to comment Share on other sites More sharing options...
EndlessLove Posted December 29, 2014 Author Share Posted December 29, 2014 (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 December 29, 2014 by EndlessLove Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now