Sign in to follow this  
Followers 0
tobias7

The right way to create AutoIt Structures

4 posts in this topic

Hello, I've been working on a program where I want a function to return a few values in one container-like variable. In C, I would've done this with a struct, but I'm not sure of the proper way to do this in AutoIt. So far, I have noticed two options. I can use an array of variants, with variants possibly being different types, which seems discouraged in the help section, or I can use DllCreateStruct to create a struct that I can use myself, but it seems that DllStructs are meant to be used for working with dlls. Thanks for any info in advance!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I've seen the DllStruct functions used for things other than Dlls. I recommend using the DllStruct method. If you make a function to iterate over an array you would lose a bit to having autoit evaluate all those tokens(keywords/functions/operators) as it's doing the loop : \.

Edited by gamerman2360

Share this post


Link to post
Share on other sites

AutoIt only supports one datatype, variant. So don't feel that you can't return the data as an array with all different datatypes in its various elements. As long as you do it in an organized fashion, you should be fine. The reason this is discouraged in the help file is probably because putting all different datatypes into an array can be really confusing to beginners. Assuming that you have worked with C, you should probably be fine in the organization department. As long as you properly name your array and keep track of which elements are of which datatype, you shouldn't have any problems. You can't get errors in autoit from using an incorrect dataype because as I mentioned earlier, AutoIt only supports one datatype. Implicit conversion of datatypes is ok to do in AutoIt.

As you said, DllStructs are another way to go, but they are really only supposed to be used for Dlls and since you don't seem to be using a dll, I would recommend that you return an array. I don't see the point in over complicating your script by using dll structs when you don't have to.

I hope I have helped you in reaching your decision.

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Thank you guys very much for your help.

Share this post


Link to post
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
Sign in to follow this  
Followers 0