Sign in to follow this  
Followers 0
amel27

Tow small questions about using structures in UDF

3 posts in this topic

#1 ·  Posted (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 by amel27

Share this post


Link to post
Share on other sites



$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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0