amel27 Posted June 25, 2008 Posted June 25, 2008 (edited) $t = DllStructCreate("int") DllStructSetData($t, 1, 111) ; Question 1: Is Structures passed ALWAYS "ByRef"? ConsoleWrite(DllStructGetData($t,1)&@CRLF) _Test1($t) ConsoleWrite(DllStructGetData($t,1)&@CRLF&@CRLF) ; Question 2: Is Structures returned ALWAYS By Reference too? ConsoleWrite(DllStructGetPtr($t)&@CRLF) $u=_Test1($t) ConsoleWrite(DllStructGetPtr($u)&@CRLF&@CRLF) Func _Test1($x) DllStructSetData($x, 1, 888) ; ReSet Structure Return $x EndFunc Edited June 25, 2008 by amel27
PsaltyDS Posted June 25, 2008 Posted June 25, 2008 $t = DllStructCreate("int") DllStructSetData($t, 1, 111) ; Question 1: Is Structures passed ALWAYS "ByRef"? ConsoleWrite(DllStructGetData($t,1)&@CRLF) _Test1($t) ConsoleWrite(DllStructGetData($t,1)&@CRLF&@CRLF) No. It's not ByRef, but it is a kind of pointer variant deep in its hidden AutoIt heart. ; Question 2: Is Structures returned ALWAYS By Reference too? ConsoleWrite(DllStructGetPtr($t)&@CRLF) $u=_Test1($t) ConsoleWrite(DllStructGetPtr($u)&@CRLF&@CRLF) Func _Test1($x) DllStructSetData($x, 1, 888); ReSet Structure Return $x EndFunc Again, since it is kind of a hidden pointer, $u = $t gets you the same struct. To show that it is not ByRef, try this: $t = DllStructCreate("int") DllStructSetData($t, 1, 111) ; Question 1: Is Structures passed ALWAYS "ByRef"? ConsoleWrite(DllStructGetData($t,1)&@CRLF) _Test1($t) ConsoleWrite(DllStructGetData($t,1)&@CRLF&@CRLF) ; Question 2: Is Structures returned ALWAYS By Reference too? ConsoleWrite(DllStructGetPtr($t)&@CRLF) $u=_Test1($t) ConsoleWrite(DllStructGetData($t,1)&@CRLF) ConsoleWrite(DllStructGetData($u,1)&@CRLF) ConsoleWrite(DllStructGetPtr($u)&@CRLF&@CRLF) Func _Test1($x) ; Create new struct over old $x = DllStructCreate("int") DllStructSetData($x, 1, 888); Set struct data ConsoleWrite("_Test1: struct $x: " & DllStructGetData($x, 1) & @LF) Return $x EndFunc Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
amel27 Posted June 26, 2008 Author Posted June 26, 2008 No. It's not ByRef, but it is a kind of pointer variant deep in its hidden AutoIt heart.Thanks for answer! Yes, I see that structures works by pointers - direct passing have increment internal AutoIT counter of pointers, passing ByRef use original pointer. But it is not obvious that structures must work as Objects (via pointers) rather than as Arrays (via data).
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now