Jump to content

Pls help me understand AutoIt language "$tag" usage


Recommended Posts

I'm a bit baffled concerning the proper declaration and usage of $tag structures in the AutoIt language (i.e., not MP3 or XML tags or the like).

Let's start with a pre-defined tag, see: Keyword $tagRECT

Since that doc page says that $tagRECT is a "keyword", I assume that means that one doesn't have to declare or define the tag, but rather just use it as you would any other language keyword. But how? The Help file isn't very helpful at all on this subject, and searching the fora overwhelmingly leads to posts about MP3 & XML tags and the like.

And what about user-defined tags? How are they declared and used?

Thank you for any guidance and education you may provide!

Link to comment
Share on other sites

Hello. It really does not mean a  keyword (talking about programming defined/reserved keyword)

 

It really is just a constant  string that representing the structure fields.

 

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Thanks, Danyfirex, for that clue. That helps a bit, possibly enough to get me started on the right track.

But some kind of help file/thread or tutorial about how to use these tags would be much more helpful...

 

Link to comment
Share on other sites

Realmenete the word $tag is designed for convenience. It need not be so strictly . 

It's just to maintain a more readable code. $tag is simply a programming suffix. You can choose the one you feel more confortable.

I used to use $sTag instead $tag

For Example

;AutoIt's  suggestion
Global Const $tagRECT = "struct; long Left;long Top;long Right;long Bottom; endstruct"
Local $tStructure=DllStructCreate($tagRECT)


;Danyfirex's one
Global Const $sTagRECT = "struct; long Left;long Top;long Right;long Bottom; endstruct"
Local $tStructure=DllStructCreate($sTagRECT)

 

Just think in this. All words that start  with the $ character is a Variable or Const. 

 

Saludos

Link to comment
Share on other sites

From Wikipedia:

Quote

A struct in the C programming language (and many derivatives) is a complex data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory, allowing the different variables to be accessed via a single pointer, or the struct declared name which returns the same address. The struct can contain many other complex and simple data types in an association, so is a natural organizing type for records like the mixed data types in lists of directory entries reading a hard drive (file length, name, extension, physical (cylinder, disk, head indexes) address, etc.), or other mixed record type (patient names, address, telephone... insurance codes, balance, etc.).

 

In your case:

Global Const $tagRECT = "struct; long Left;long Top;long Right;long Bottom; endstruct"

This is only how the data type declaration should be when you initialize it using DllStructCreate! For this tag the memory reservation is 16 bytes (4 * 4 bytes / long = 4 bytes).

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

Why did  accessing array elements are bit faster than struct elements ? Even though , struct using dynamic memory ?

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

My thanks to Danyfirex and UEZ for their replies!

To @UEZ specifically, I was already aware that tags were structs (I studied Computer Science at three different universities, certainly including Data Structures, starting back in the mid '70s), and had been a systems software developer for decades on non-PCs  -- with embedded as well as bigger machines with non-PC operating systems -- though I'm disabled now, so I'm no longer employed.  What I didn't know was exactly how to declare, create, store, retrieve data and so forth using tags specifically in AutoIt.

Now I believe I have a better idea from reading other's code that I searched out. Here's one aspect I wanted to know about: Using the pre-defined $tagRect definition...

Global $G_ImageAreaRectTag = DllStructCreate($tagRect)

It was the entire "DLLStructCreate()" portion that I could find no help file or help post regarding, and one of the reasons I posted this thread.  An additional complete unknown regarding AutoIt to me was that, apparently, all structs are DLLStructs (or at least they're accessed as if they were), which very much surprised me, especially because my code has nothing whatsoever with invoking DLLs (as noted above, recall that me entire past history of my programming experience was with non-PC / non-Windows operating systems).  Only once I started learning AutoIt did I ever program anything significant under Windows.

The other aspect I couldn't find any help with was actually how to use these tag structs.  I now have a better idea...

DllStructSetData($G_ImageAreaRectTag, "Left", 8)
DllStructSetData($G_ImageAreaRectTag, "Top", 8)
DllStructSetData($G_ImageAreaRectTag, "Right", 800)
DllStructSetData($G_ImageAreaRectTag, "Bottom", 600)

and to retrieve the data from a tag...

Local $var = DllStructGetData( $G_ImageAreaRectTag, "Right" )

 

Now that I've found these examples, I have a much better understanding of how to declare and use tags.  Thanks!

 

Link to comment
Share on other sites

Hello again. You're Welcome.

DllStructs were designed to be used in Dllcall while using windows API.

an AutoIt Developer told me some time ago that DllStructCreate were created to be strictly used with dllcalls. I'm not agree. (Because my own undestanding still says that can be used for other usefull things.)

Talking about $tagRECT Structure is used to defines the coordinates of the upper-left and lower-right corners of a rectangle.It is Useful to deal with Window. 

 

I think you should deal with Dll Structures only when is needed (or maybe for comfort) otherwise store data in normal variables.

 

In this simple example you can the easy way of using normal variables instead structures.

Local $iVar=10 ;normal Variable ;don't need to define the variable type (AutoIt variables are Variant type)
ConsoleWrite($iVar & @CRLF)

Local $tVar=DllStructCreate("int AnIntVariable")
DllStructSetData($tVar,"AnIntVariable",10);Access by element name
;~ DllStructSetData($tVar,1,10) ;Access by  element Index

ConsoleWrite(DllStructGetData($tVar,"AnIntVariable") & @CRLF) ;Access by element name
;~ ConsoleWrite(DllStructGetData($tVar,1) & @CRLF) ;Access by  element Index

 

I could not find any good use of $tagRECT than an API call.

 

#include <WinAPI.au3> 
Local $tRect = _WinAPI_GetWindowRect(WinGetHandle("[ACTIVE]")) ;get active window upper-left and lower-right corners 
;~ _WinAPI_GetWindowRect Internally creates a $tagRECT structure and returns it with filled values. 

;Print values
ConsoleWrite("Left: " & DllStructGetData($tRect, "left") & @CRLF)
ConsoleWrite("top: " & DllStructGetData($tRect, "top") & @CRLF)
ConsoleWrite("right: " & DllStructGetData($tRect, "right") & @CRLF)
ConsoleWrite("bottom: " & DllStructGetData($tRect, "bottom") & @CRLF)

 

I hope you can undestand me. I'm not English native speaker.

 

Saludos

 

 

 

 

 

 

 

 

Edited by Danyfirex
Link to comment
Share on other sites

@Mbee: A dllstruct tutorial is here. a dll call-code generator is here. For links to usage discussion, see for exaple here.

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...