Jump to content

How to get DllStruct element names and data types


Recommended Posts

     Is there a way to extract the element names and data type definitions from a DllStruct?

I have a DLLStruct with many elements and would like to set up an array that has the Datatype and element name to

display them on a generically created set of controls.   But I need to be able to insert an entry

in the DLLStruct definition when I want to,  and then,  not have to go back and renumber the array that is now out of order.

So what I want is to read the DLLStruct data and name by index.

Then load those values into the generic table. (The table consisting of labels and input boxes created in order so I can use an index value on them)

I suppose I could get the value, and use a GetVarType on it , but the element NAME string is what I define the element as and make reference to, so I would

like to be able to get that name.

 

And, is there a way to get the number of elements in the struct?  Like a Ubound function for DLLStructs...

Edited by Tyranna


 

Link to comment
Share on other sites

I've writen a function that might help a bit but it doesn't actually cover all your bases, mainly as it doesn't even try to detect and output alignment directives, including STRUCT and ENDSTRUCT. That is [painfully] possible but would require a whole lot of new code for what I consider mostly corner cases. This quick'n'dirty code requires the beta in order to support Map datatype.

There is no possibility with current AutoIt to recover structure field names, but they are essentially cosmetic. In your case, setting up a 2D array to store field name along with a float to be able to insert betwwen existing entries + sort on that column before re-creation would do. Won't work forever but a double has enough precision to be workable.

VarDump.au3

Needless to say, all this is experimental at best, buggy most probably.

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hmm.

That is some crazy coding to determine what the elements are.

This seems to imply that if you want to know what element you want, you have to memorize the struct definition itself.

That simply cannot happen.

Especially if the structure definition is changing when new entries are added or deleted.

The Idea of adding a sort column is cool,  but the definition is already in place and I cant(wont) change the mile long thing.

I did have an idea though, and it goes something like this:

1.)  Store the Struct Elements and Types fields in a CSV file.  Ex: LINE1: "BYTE" , "ELEMENT1[20]"

2.)  Parse those into an array using 1-based index and 0 being the total elements in the struct

3. ) Create the struct definition from the array entries with concatenation.

Then maybe I could just go to the file and add an entry where ever I wanted to and could read the ELEMENTNAME from the array.

Then the Array element number could match the index of the Struct as well

Creating the original file would be very tedious work.....

What do you think?

 

 

 


 

Link to comment
Share on other sites

28 minutes ago, Tyranna said:

This seems to imply that if you want to know what element you want, you have to memorize the struct definition itself.

That simply cannot happen.

Ahem, this is just what you do in the 1) 2) 3) points in your post.

I suggested an all-embedded way to do it. Relying on reading/editing of an external file wasn't in the original landscape, at least as I viewed it.

And yes, I had "some" fun dumping actual precise content of variables.

May I ask why you need such dynamically changing C structures?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I would have to respectfully disagree with the assessment that that is what i was doing in step 1,2, and 3. 

Because, at that point I can link the elementname with the index of the struct.

I do not want to have to go look at the struct definition every time I want to know the element name or vice versa.

I want to use the element name to derive the struct index.

I can access the struct with the name, or index, but to a loop outputting formatted output, it cant see the name at all.

I would end up with a list of data labeled 1,2,3,4,5,6,7,8 etc, which when all the data is numbers, would mean nothing

when displayed in table format.  That is why I want to get the name, so I can display the elements data and its corresponding name(Label)

I suppose i am using a struct as a database.  Maybe that's not a proper implementation for a database.  But, since the DLLStruct has that

elementname parameter that you can use to access the specific struct data it seemed to me, in my mind a perfect fit. At least until

I found  that I can't use the elementname.  Obviously somewhere in AutoIt there is a mapping from the struct elementname to the struct index,

because it maps it to it in the DLLStructGetData command.  It was an intuitive leap that I would be able to access that mapping somewhere.

 


 

Link to comment
Share on other sites

The DllStructAnalyze and supporting functions are in the spoiler (Reveal hidden contents) of Ward's first post.


His example crashes though, at least when I tried executing it.  Has potential though.

Edited by spudw2k
Link to comment
Share on other sites

Well, I implemented the file method with an asscociated array for referencing the elementname and it works well.

It is a round-about, but I can edit the file, and it re-creates the Struct by concatenating the array elements.

 

 


 

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