Sign in to follow this  
Followers 0
Yashied

Pointer to a variable

6 posts in this topic




Not in AutoIt.

Unless you do it with a DLL struct:
; Create the struct and get it's pointer
Global $iA = 16
Global $tagA = "int A"
Global $tA = DllStructCreate($tagA)
Global $ptA = DllStructGetPtr($tA)

; Set the data
DllStructSetData($tA, "A", $iA)

; Use the pointer to extract the data
MsgBox(64, "DLL Success Test", "A = " & _GetData($ptA) & @CRLF & "@error = " & @error)

; Force an error
$ptA = 0
MsgBox(16, "DLL Error Test", "A = " & _GetData($ptA) & @CRLF & "@error = " & @error)

Func _GetData($ptPointer)
    Local $tRET = DllStructCreate($tagA, $ptPointer)
    Local $iRET = DllStructGetData($tRET, 1)
    Return SetError(@error, 0, $iRET)
EndFunc  ;==>_GetData

In this example, you can't get the pointer to $iA directly, but you can copy $iA into a struct and get the pointer of that.

:P


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

#4 ·  Posted (edited)

Unless you do it with a DLL struct:

; Create the struct and get it's pointer
Global $iA = 16
Global $tagA = "int A"
Global $tA = DllStructCreate($tagA)
Global $ptA = DllStructGetPtr($tA)

; Set the data
DllStructSetData($tA, "A", $iA)

; Use the pointer to extract the data
MsgBox(64, "DLL Success Test", "A = " & _GetData($ptA) & @CRLF & "@error = " & @error)

; Force an error
$ptA = 0
MsgBox(16, "DLL Error Test", "A = " & _GetData($ptA) & @CRLF & "@error = " & @error)

Func _GetData($ptPointer)
    Local $tRET = DllStructCreate($tagA, $ptPointer)
    Local $iRET = DllStructGetData($tRET, 1)
    Return SetError(@error, 0, $iRET)
EndFunc;==>_GetData

In this example, you can't get the pointer to $iA directly, but you can copy $iA into a struct and get the pointer of that.

:P

Your structure is global. No need for _GetData() function:

MsgBox(64, "DLL Success Test", "A = " & DllStructGetData($tA, 1))

Same thing as for pointer :unsure: thoug I can see what could be your point(er).

Yashied likely meant something else.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Your structure is global. No need for _GetData() function:

MsgBox(64, "DLL Success Test", "A = " & DllStructGetData($tA, 1))

Same thing as for pointer :unsure: thoug I can see what could be your point(er).

Yashied likely meant something else.

trancexx, you are right. I want to access a variable (not structure) knowing only the address and type. But I think that this is not possible in AutoIt (different syntax). Although the structure is the same, but less convenient than a direct appeal to the variable.

:P

Share this post


Link to post
Share on other sites

trancexx, you are right. I want to access a variable (not structure) knowing only the address and type. But I think that this is not possible in AutoIt (different syntax). Although the structure is the same, but less convenient than a direct appeal to the variable.

:unsure:

All AutoIt variables are a C-type variant, and the properties of the variant for the different AutoIt variable types is not meant to be exposed to the scripter. Valik doesn't even like that the VarGetType() function exists.

So even if you got a pointer to the $a variable, it would be to a variant that required more processing to see that it was a variant containing an INT32 and where the actual value was. At least that's my understanding from a non-C programmer peek behind the curtain. Smarter people can and often do correct me.

:P


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

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