Jump to content

What does ptr() do?


Smorg
 Share

Recommended Posts

http://www.autoitscript.com/autoit3/docs/functions/Ptr.htm

Yes that would be what I read. This contains neither examples nor explanations. How is this useful? It just returns a pointer but provides no way of using it? Just there for your information or something? My guess is no because it has it's own datatype.

$x = ptr(1)
msgbox(0, '', VarGetType($x))
Alright clearly autoit remembers this is a ptr, not a string or number.

$x = ptr(1)
msgbox(0, '', addOne($x))


Func addOne($x)
    return $x + 1
EndFunc

ptr + int = ptr? That must be wrong.

Edited by Smorg
Link to comment
Share on other sites

This is supposed to return pointers? Why does it only accept expressions and not functions with free variables? How do you dereference these "expressions"? Could someone maybe show some example usage?

Reading the help file answers all of your questions

Returns the pointer representation of the expression.

Converts an expression into a pointer variant.

And I'm afraid I do not understand what you mean by dereference...

As for adding numbers to your string, that is impossible. "Hello" + "1" = ...? You can add strings together "Hello " + "there" = "Hello there" and you can add numbers together "1" + "2" = "3" But you cannot mix the two.

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

  as mentioned before...

Returns the pointer representation of the expression.

$number=2345            ;some number could be a pointer
ConsoleWrite("Q: Is "&$number&" a Pointer?   A: "& (isptr($number)=1) & @crlf)

$no_pointer1="0x"&hex($number,4)         ;looks like a pointer
ConsoleWrite("Q: Is "&$no_pointer1&" a Pointer?   A: "& (isptr($no_pointer1)=1) & @crlf)

$no_pointer2="0x"&hex($number)            ;looks more like a pointer
ConsoleWrite("Q: Is "&$no_pointer2&" a Pointer?   A: "& (isptr($no_pointer2)=1) & @crlf)

$pointer=ptr($number)        ;a way to get a pointer
ConsoleWrite("Q: Is "&$pointer&" a Pointer?   A: "& (isptr($pointer)=1) & @crlf&@crlf)


$struct=DllStructCreate("dword[5]")
$pointer=DllStructGetPtr($struct)       ;an other way to get a pointer
ConsoleWrite("Q: DllStructGetPtr returns a pointer?    A: "& (isptr($pointer)=1)& @crlf)

for $i=1 to 5   ;every index of the struct
    $adress_dword=$pointer + 4 * $i    ;adress of each dword
    ConsoleWrite("Is the calculated adress "&$adress_dword&" of the dword a pointer?   A: "&(isptr($adress_dword)=1)&@crlf)
next
 
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...