Jump to content

Please explain the DllStructCreate(Struct, Pointer) syntax!


Recommended Posts

From the documentation of DllStructCreate(), it can be called using the following syntax:

DllStructCreate(Struct, Pointer)
Struct A string representing the structure to create (See Remarks).
Pointer [optional] If supplied the struct will not allocate memory but use the pointer supplied.

Would somebody here explain the usage of Pointer parameter clearly with some examples?

Thank's in advance.

Edited by tukangusil7
Link to comment
Share on other sites

basically you are giving a reference to an already created data structure you are just defining what it contains to AutoIt

below is an entirely contrived example but it gives you the idea, typically the pointer would be returned from an API function

$tInit = DllStructCreate("BYTE[8]")
DllStructSetData($tInit, 1, 0xFF, 1)
DllStructSetData($tInit, 1, 0xEE, 2)
DllStructSetData($tInit, 1, 0xDD, 3)
DllStructSetData($tInit, 1, 0xCC, 4)
DllStructSetData($tInit, 1, 0x11, 5)
DllStructSetData($tInit, 1, 0x22, 6)
DllStructSetData($tInit, 1, 0x33, 7)
DllStructSetData($tInit, 1, 0x44, 8)

$tInitPtr = DllStructCreate("BYTE[4]", DllStructGetPtr($tInit)) ; Using a pointer $tInit
For $i = 1 To 4 ; Show Contents
    ConsoleWrite("0x" & Hex(DllStructGetData($tInitPtr, 1, $i)) & @CRLF)
Next

; Setting the data here affects the original data
DllStructSetData($tInitPtr, 1, 0xBB, 1)
DllStructSetData($tInitPtr, 1, 0xAA, 2)
DllStructSetData($tInitPtr, 1, 0x99, 3)
DllStructSetData($tInitPtr, 1, 0x88, 4)

ConsoleWrite(@CRLF)
For $i = 1 To 4
    ConsoleWrite("0x" & Hex(DllStructGetData($tInit, 1, $i)) & @CRLF)
Next

;lets start at second element (DllStructGetPtr($tInit) + 0 ) is initial (first) element
ConsoleWrite(@CRLF)
$tInitPtr = DllStructCreate("BYTE[4]", DllStructGetPtr($tInit) + 1)
For $i = 1 To 4
    ConsoleWrite("0x" & Hex(DllStructGetData($tInitPtr, 1, $i)) & @CRLF)
Next

;lets start at third element
ConsoleWrite(@CRLF)
$tInitPtr = DllStructCreate("BYTE[4]", DllStructGetPtr($tInit) + 2)
For $i = 1 To 4
    ConsoleWrite("0x" & Hex(DllStructGetData($tInitPtr, 1, $i)) & @CRLF)
Next

;lets start at fourth element
ConsoleWrite(@CRLF)
$tInitPtr = DllStructCreate("BYTE[4]", DllStructGetPtr($tInit) + 3)
For $i = 1 To 4
    ConsoleWrite("0x" & Hex(DllStructGetData($tInitPtr, 1, $i)) & @CRLF)
Next

 

Link to comment
Share on other sites

Hi,

the "struct" reserves some memory, and the "pointer" points to the first adress of this memory.

Here an (not season related^^)  example which demonstrates the usage of the so called "memory" (which belongs to NOTHING! (meaning the datatypes) )

;create struct
$struct =dllstructcreate("int;float[4];dword")

;fill struct with data
dllstructsetdata($struct,1,123456);int
dllstructsetdata($struct,2,4.80114160043301e+030,1);float
dllstructsetdata($struct,2,3.68584191575527e+024,2);float
dllstructsetdata($struct,2,7.71403089381636e+031,3);float
dllstructsetdata($struct,2,8.24605444209785e-019,4);float
dllstructsetdata($struct,3,0xDEADBEEF);dword

;read some data from struct at offset 4
$struct2=dllstructcreate("char[16]",dllstructgetptr($struct)+4)
msgbox(0,":o)",dllstructgetdata($struct2,1))

 

Link to comment
Share on other sites

  • Moderators

RTFC,

Any explanation that refers to IKEA furniture cannot, by definition, be considered "simple"! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23: Darn, you've got me there! Always wondered why struct definitions look like flatpacks. :lol:

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

×
×
  • Create New...