NewtonScripter Posted June 24, 2008 Share Posted June 24, 2008 I was wondering if structures like in vBasic are possible in Autoit. I tried it vBasic's way, Structure Foo ... End Structure But it didn't work Link to comment Share on other sites More sharing options...
FreeFry Posted June 24, 2008 Share Posted June 24, 2008 The only structures I know of in AutoIt is the ones created by DllStructCreate. Link to comment Share on other sites More sharing options...
nobbe Posted June 25, 2008 Share Posted June 25, 2008 we had this thread beforeautoit has only one variable type (the variant)another idea may be to setup variable names with prefixsoType SettingInfoAppID As StringCurrentPath As StringUserName As StringPassword As StringExpirationDate As DateUsageCount As IntegerAccessLevel As IntegerAllowChanges As BooleanEnd Typecould be$SettingInfo_AppID =" 123"$SettingInfo_CurrentPath = "C:\Something\"$SettingInfo_UsageCount = 3and so on ..or you may even more use variables following the "Hungarian notation" to give them better naming structurehttp://en.wikipedia.org/wiki/Hungarian_notationwhich could maybe look like$SettingInfo_sz_AppID =" 123"$SettingInfo_sz_CurrentPath = "C:\Something\"$SettingInfo_i_UsageCount = 3 Link to comment Share on other sites More sharing options...
FreeFry Posted June 25, 2008 Share Posted June 25, 2008 I usually just name my variables/arrays, etc. with the AutoIt type they represent, ie:I would name an array called names $aNames.A number called NumBoxes I would name $iNumBoxes.I also tend to name boolean variables with the "i" prefix too($iPaused).Handles I differ a little bit on, I tend to call them $iWindowHandle, or $hWindow, or sometimes $hWndWin.I haven't come to a conclusion yet about what I should name structures(DllStructCreate ones), but I tend to call them $struct_SomeName, but perhaps I'll go with the $stSomeName naming method mentioned in the wiki link nobbe gave. Also in my functions I usually add a v inside the name, like $avNames, or $ivNumBoxes, this to make the names a lil more unique. But I usually only name my variables/arrays/etc. like this inside functions, outside functions, in the "main" code, I usually skip the value type naming, and name them with something more Readable, like $NumerOfBoxes, $PeopleNames, or some of the sort. Link to comment Share on other sites More sharing options...
hexspace Posted June 25, 2008 Share Posted June 25, 2008 Check out the DllStructCreate.au3. It might help. ;========================================================= ; Create the struct ; struct { ; int var1; ; unsigned char var2; ; unsigned int var3; ; char var4[128]; ; } ;========================================================= $str = "int var1;ubyte var2;uint var3;char var4[128]" $a = DllStructCreate($str) if @error Then MsgBox(0,"","Error in DllStructCreate " & @error); exit endif ;========================================================= ; Set data in the struct ; struct.var1 = -1; ; struct.var2 = 255; ; struct.var3 = INT_MAX; -1 will be typecasted to (unsigned int) ; strcpy(struct.var4,"Hello"); ; struct.var4[0] = 'h'; ;========================================================= DllStructSetData($a,"var1",-1) DllStructSetData($a,"var2",255) DllStructSetData($a,"var3",-1) DllStructSetData($a,"var4","Hello") DllStructSetData($a,"var4",Asc("h"),1) ;========================================================= ; Display info in the struct ;========================================================= MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _ "Struct pointer: " & DllStructGetPtr($a) & @CRLF & _ "Data:" & @CRLF & _ DllStructGetData($a,1) & @CRLF & _ DllStructGetData($a,2) & @CRLF & _ DllStructGetData($a,3) & @CRLF & _ DllStructGetData($a,4)) I was wondering if structures like in vBasic are possible in Autoit. I tried it vBasic's way, Structure Foo ... End Structure But it didn't work Link to comment Share on other sites More sharing options...
NewtonScripter Posted June 25, 2008 Author Share Posted June 25, 2008 The DllStructCreate.au3 sounds great Do I have to import that file like a library file in C? How do I do that? Also I don't understand this line: DllStructGetData($a,1) & @CRLF & _ What is "& @CRLF & _" ? Thanks Link to comment Share on other sites More sharing options...
martin Posted June 25, 2008 Share Posted June 25, 2008 The DllStructCreate.au3 sounds greatDo I have to import that file like a library file in C?How do I do that? Also I don't understand this line: DllStructGetData($a,1) & @CRLF & _What is "& @CRLF & _" ?ThanksDllStructCreate is a built in function you don't need any include file, see te help. "DllStructCreate.au3" was a mistake I think.The lines DllStructGetData($a,1) & @CRLF & _are just lines to be output in the message box. In AutoIt a space followed by an underline character at the end of a line is a way to break a line up but still have the interpreter consider it as one whole line.So the two lines in a script like this:$abcd + _$efghare equivalent to $abcd + $efgh Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
crashdemons Posted August 15, 2008 Share Posted August 15, 2008 sorry to revive this quasi-old thread, I know how to create the generic structs manually etc. but am facing a couple of more complicated issues... but how would I manage the two following things: -Load a file's data into a struct without manually splitting the data and setting each element by hand (ex: loading a program into a IMAGE_DOS_HEADER struct) -create a nested struct - or at least use the above^ method and load the nested structure as a BYTE[] value and turn it into the struct later... just a little bit of an issue... most of it is caused by the following structures IMAGE_NT_HEADER='ULONG Signature; FileHeader; OptionalHeader' IMAGE_OPTIONAL_HEADER='USHORT Magic;CHAR MajorLinkerVersion;CHAR MinorLinkerVersion;ULONG SizeOfCode;ULONG SizeOfInitializedData;ULONG SizeOfUninitializedData;ULONG AddressOfEntryPoint;ULONG BaseOfCode;ULONG BaseOfData;ULONG ImageBase;ULONG SectionAlignment;ULONG FileAlignment;USHORT MajorOperatingSystemVersion;USHORT MinorOperatingSystemVersion;USHORT MajorImageVersion;USHORT MinorImageVersion;USHORT MajorSubsystemVersion;USHORT MinorSubsystemVersion;ULONG Win32VersionValue;ULONG SizeOfImage;ULONG SizeOfHeaders;ULONG CheckSum;USHORT Subsystem;USHORT DllCharacteristics;ULONG SizeOfStackReserve;ULONG SizeOfStackCommit;ULONG SizeOfHeapReserve;ULONG SizeOfHeapCommit;ULONG LoaderFlags;ULONG NumberOfRvaAndSizes;DataDirectories[16]' IMAGE_DATA_DIRECTORY='ulong VirtualAddress; ulong Size' IMAGE_FILE_HEADER='USHORT Machine;USHORT NumberOfSections;ULONG TimeDateStamp;ULONG PointerToSymbolTable;ULONG NumberOfSymbols;USHORT SizeOfOptionalHeader;USHORT Characteristics' as you can see, IMAGE_NT_HEADER includes 2 structs inside itself, one of which includes 16 of a third struct so - any clue how to manage this without alot of hassle, or am I out of my mind? My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 15, 2008 Moderators Share Posted August 15, 2008 sorry to revive this quasi-old thread, I know how to create the generic structs manually etc. but am facing a couple of more complicated issues... but how would I manage the two following things: -Load a file's data into a struct without manually splitting the data and setting each element by hand (ex: loading a program into a IMAGE_DOS_HEADER struct) -create a nested struct - or at least use the above^ method and load the nested structure as a BYTE[] value and turn it into the struct later... just a little bit of an issue... most of it is caused by the following structures IMAGE_NT_HEADER='ULONG Signature; FileHeader; OptionalHeader' IMAGE_OPTIONAL_HEADER='USHORT Magic;CHAR MajorLinkerVersion;CHAR MinorLinkerVersion;ULONG SizeOfCode;ULONG SizeOfInitializedData;ULONG SizeOfUninitializedData;ULONG AddressOfEntryPoint;ULONG BaseOfCode;ULONG BaseOfData;ULONG ImageBase;ULONG SectionAlignment;ULONG FileAlignment;USHORT MajorOperatingSystemVersion;USHORT MinorOperatingSystemVersion;USHORT MajorImageVersion;USHORT MinorImageVersion;USHORT MajorSubsystemVersion;USHORT MinorSubsystemVersion;ULONG Win32VersionValue;ULONG SizeOfImage;ULONG SizeOfHeaders;ULONG CheckSum;USHORT Subsystem;USHORT DllCharacteristics;ULONG SizeOfStackReserve;ULONG SizeOfStackCommit;ULONG SizeOfHeapReserve;ULONG SizeOfHeapCommit;ULONG LoaderFlags;ULONG NumberOfRvaAndSizes;DataDirectories[16]' IMAGE_DATA_DIRECTORY='ulong VirtualAddress; ulong Size' IMAGE_FILE_HEADER='USHORT Machine;USHORT NumberOfSections;ULONG TimeDateStamp;ULONG PointerToSymbolTable;ULONG NumberOfSymbols;USHORT SizeOfOptionalHeader;USHORT Characteristics' as you can see, IMAGE_NT_HEADER includes 2 structs inside itself, one of which includes 16 of a third struct so - any clue how to manage this without alot of hassle, or am I out of my mind? Take a look at DllStructCreate's second parameter: Local $IMAGE_OPTIONAL_HEADER = DllStructCreate("all the data") Local $pIMAGE_OPTIONAL_HEADER = DllStructGetPtr($IMAGE_OPTIONAL_HEADER) Local $IMAGE_DATA_DIRECTORY = DllStructCreate("all its data", $pIMAGE_OPTIONAL_HEADER) Local $pIMAGE_DATA_DIRECTORY = DllStructGetPtr($IMAGE_DATA_DIRECTORY) Local $IMAGE_FILE_HEADER = DllStructCreate("all its data", $pIMAGE_OPTIONAL_HEADER) Local $pIMAGE_FILE_HEADER = DllStructGetPtr($IMAGE_FILE_HEADER) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
crashdemons Posted August 16, 2008 Share Posted August 16, 2008 I thought I tried that once before and the values just got screwed up (figured I was doing it kinda hackish also since I hadn't seen it done before) Although, I had written out what I was doing so I could actually use arrays, because some things were just easier. (should be convert-able back though if need be) My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) 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