Jump to content

Are pointers to variables and functions possible?


martin
 Share

Recommended Posts

I know that you can use DllStructCreate to store a variable at an address, or use DllStructGetPtr to find the address, but can the address of a variable be found, and can pointers be used in any way in AutoIt apart from using DllStructs?

Like in C for example,

Int *pVar

.

.

pvar = &Var3

.

.

. *pVar = 9

Is any equivalent possible in AutoIt?

AdLibEnable and GuiRegisterMsg are examples of functions in AutoIt which appears to point to the function to run, so how could that be done otherwise?

For example, if you created a timer with the SetTimer API, then it is possible to pass it the address of a function to run, but how could I do that?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks Larry. I hadn't looked at that before, and now that I have my head hurts!

As I understand what I just looked at, Piccaso creates a piece of code in memory which calls the functions you want to use, and gives the address of where that piece of code is so that you can pass that address to the function for the routine to call.

I'll have a play with it.

But it doesn't help with using pointers and addresses for variables etc does it ?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

DllStructCreate and DllStructGetPtr:

$struct = DllStructCreate("int;char")
DllStructSetData($struct, 1, 467)
DllStructSetData($struct, 2, "abcdef")

$pointer1 = DllStructGetPtr($struct, 1); pointer to integer variable
$pointer2 = DllStructGetPtr($struct, 2); pointer to string variable
Edited by Zedna
Link to comment
Share on other sites

what do you need for pointer to variable?

I don't but I'm interested to see how to share data between programs. If you set up an area of memory it would be easier to use pointers and addresses so that when a variable changes it could be written directly to the shared memory.

and timer is like...

#include "DllCallBack.au3"

$hwin = WinGetHandle(AutoItWinGetTitle())

$hStub_Timer = _DllCallBack ("TimerProc", _ ; Name of the function
                                   "hwnd;int;ptr;int")           

$h = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hwin, "int", 0, "int", 5000, "ptr", $hStub_Timer)

While 1
    Sleep(20)
WEnd

Func OnAutoItExit()
    DllCall("user32.dll","int","KillTimer","hwnd",$hwin,"int",$h[0])
EndFunc

Func TimerProc($hwnd,$uMsg,$idEvent,$dwTime)
    ToolTip($hwnd&@LF&$uMsg&@LF&$idEvent&@LF&$dwTime)
EndFunc
Now he tells me! Thanks Larry, I just spent over an hour working out how to use callbacks for some timers. The only thing I did which you didn't in your example is give the timers ID numbers so that when one times out you know which one it is. I posted it here.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...