Jump to content

Linked list of complex Structures?


Recommended Posts

Hello to all here,

i'm new to AutoIt and i hope that i'm posting to the correct forum.

I encounter some problems on definening a multi-nested struct (with arrays of pointers to other structs).

i think i searched the whole forum about a solution or hints, but either i was unable to find it, overlooked it or i simply does not yet exist (i found a simple example in a german formun on how to create a nested structure, but wasn't able or i do not understand on how to adapt it for my particulare purpose).

what i'm trying to reach is, to have a table in which i define all from an application called windows and its associated ctrls that i have to test, fill the table with data run a loop on that table.

in other words...

As the main Application calls other command specific Windows i want to collect all that stuff and map it in one big table which i can work down in a loop.

i post the c struct so you may have an idea what im searching for.

i already spent a lot of time to get tagMainStruct and tagAppStruct together, but i didn't reach further.

what i tried is, i defined pTabs[8] as addressholders (ulong_ptr) and then created each single tab struct and stored the returned value from DllStructCreate in that pTabs.

same for the other struct.

but when i retrieve the address from the array of pointers and pass this address to the DllStructGetData i get an error 6 or 7 (i don't remember rigth now)

my questions are as follows:

q1: can the below showed nested struct be created in AutoIt?

q2: if yes, can someone give me a hint on how to do it?

i hope its almost clear what i want

and

any help is much appreciated

regards

lo - level - user

CODE

#define nMainWnds 9

#define nTabCount 8

#define nButtonCount 5

/*

Struct Declaration Section

=========================================================

C Like Struct

typedef struct {

int nSize; // struct size : version identifier

int nButtonId; // control id

hwnd hButton; // ctrl handle

char szCmd[1024]; // reserved

char szArgs[256]; // reserved

char szParams[256] // reserved

}tagBtnStruct, *PTBTNSTRUCT;

typedef struct {

int nSize; // struct size : version identifier

char szTabName[50]; // Tab caption

hwnd hTab; // handle to the tabcontrol : type SysTabCtrl32

int iTab; // 0 based index of Tab

short nButtonCnt; // ammount of Buttons

PTBTNSTRUCT pButtons[nButtonCount]; // --> array of pointers to button struct : each pointer represents a button

}tagTabStruct, *PTTABSTRUCT;

typedef struct {

int nSize; // struct size : version identifier

char szWndName[50]; // application or window caption

hwnd hWnd; // handle to window / application

short nTabCount; // > 0 has a Tab Ctrl with nTabCount Tabs

PTTABSTRUCT pTabs[nTabCount]; // --> array of pointers to tab struct : each pointer represents a tab with all the needed data

}tagAppStruct, *PTAPPSTRUCT;

typedef struct {

int nSize; // struct size : version identifier

tagAppStruct tAppStruct[nMainWnds];

}tagMainStruct, *PTMAINSTRUCT;

tagMainStruct tMainStruct;

tMainStruct.tAppStruct.pTabs = (PTTABSTRUCT)malloc(sizeof(tagTabStruct)*nTabCount)

tMainStruct.tAppStruct.pTabs->pButtons = (PTBTNSTRUCT)malloc(sizeof(tagBtnStruct)*nButtonCount)

=========================================================

*/

Link to comment
Share on other sites

There is no way to create a proper linked list in AutoIt. AutoIt lacks the ability to allocate memory on the fly, so every time you call DllStructCreate using the same variable name the old data is lost. The only way around this is to use an array to store all of the DllStructCreate handles, thereby defeating the purpose of a linked list.

You are better off using other options.

SQLite

Nested Arrays

Scripting.Dictionary array

Link to comment
Share on other sites

One way is to create two arrays, both with the same amount of rows, have the 1st array have, besides the extra data, indexes into a. the previous item index and b. the next item index, then use the resultant index to access the other (main data) array. ReDim's would be necessary for both arrays as well as some maintenance code, and also a 'free node' index list.

It's all very possible - the good algorithm books would probably give you an idea of how to create a linked list inside an array (or two in this case)

Note that strings would best be done as they are in AutoIT, and moving it to a DLL call would involve using DLLStructCreate (or keeping a global one for faster use) and filling in the empty spots.

*Edit: I just realized that the structure itself requires pointers in it - this would make it nearly impossible to do it as I recommended. Woops!

Edited by ascendant
Link to comment
Share on other sites

hello weaponx && ascendant

sorry for the late response. was doing other work

and thanks for the confirmation and info. i was imaging that this were nearby impossible.

i redefined the structdefinition and builded it a little bit less complex (without array of pointers) and created something like a mix of the things you both said.

defined 2d arays for each structure definition in which one filed reprents the matching key for search purpose in the other arrays and one field which holds the data (pointers) returned by DllSctructCreate. so at least i can go trough the array and do the whole work from there.

thanks again for the quick response.

keep it real

regards

lo - level -user

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