Infinite Posted December 25, 2005 Share Posted December 25, 2005 Could anyone tell me how I could get the address/pointer of a function? I want to pass a functions address as a argument but I can't find a way to get the address. Something like this but for a function would be nice: Dim $MyVal = DllStructCreate("int") DllStructSetData($MyVal, 1, 123) Dim $MyPtr = DllStructGetPtr($MyVal) MsgBox(0, "Value & Address", "Value: " & DllStructGetData($MyVal, 1) & @CRLF & "Address: " & $MyPtr) Dim $MyDllVal = DllCall("MyDll.dll", "int", "ReturnValue", "int", $MyPtr) MsgBox(0, "Value from DllCall", "Value: " & $MyDllVal[0]) And the code of the dll: int ReturnValue(int *pInt) { return *pInt; } Link to comment Share on other sites More sharing options...
MrSpacely Posted December 25, 2005 Share Posted December 25, 2005 Could anyone tell me how I could get the address/pointer of a function? I want to pass a functions address as a argument but I can't find a way to get the address. Something like this but for a function would be nice: Dim $MyVal = DllStructCreate("int") DllStructSetData($MyVal, 1, 123) Dim $MyPtr = DllStructGetPtr($MyVal) MsgBox(0, "Value & Address", "Value: " & DllStructGetData($MyVal, 1) & @CRLF & "Address: " & $MyPtr) Dim $MyDllVal = DllCall("MyDll.dll", "int", "ReturnValue", "int", $MyPtr) MsgBox(0, "Value from DllCall", "Value: " & $MyDllVal[0]) And the code of the dll: int ReturnValue(int *pInt) { return *pInt; } The function doesn't support that there only exists byref wich looks a little like one of the pointer things in c++ Link to comment Share on other sites More sharing options...
Infinite Posted December 25, 2005 Author Share Posted December 25, 2005 Okay, what I want to do is get the address of the actual function not any variable I pass into it. Here's an example I quickly put together in C (untested): #include <Stdio.h> void MyFunction1(int x, int y, int &rz) { rz = x + y; } void MyFunction2(int x, int y, int &rz) { rz = x * y; } int PtrFunction(void (*pFunc)(int, int, int&), int &x, int &y) { int z; pFunc(x, y, z); return z; } int main() { int x = 5; int y = 10; int z; void (*pFunc)(int, int, int&); pFunc = MyFunction1; z = PtrFunction(pFunc, x, y); printf("%d\n", z); pFunc = MyFunction2; z = PtrFunction(pFunc, x, y); printf("%d\n", z); return true; } As you can see PtrFunction takes as its first argument a pointer to a function that takes 3 ints and returns nothing. What im trying to do is make a function in an AutoIt script and pass the address of that into a dll. Example (won't work): Func MyFunction($x, $y) Return $x + $y EndFunc Dim $FuncPtr = MyFunction ; Code to pass $FuncPtr into dll goes here Exit I'm starting to believe that what I am trying to do is impossible so don't think too hard about it Link to comment Share on other sites More sharing options...
Infinite Posted December 25, 2005 Author Share Posted December 25, 2005 (edited) Just looked at the AutoIt source. I don't think what I want to do is possible. From what I briefly read I think what happens is AutoIt jumps to the line where you declare your function then reads and executes till the line with the EndFunc command then jumps back to where it was. Sorry to bother ya'll Edited December 25, 2005 by Infinite Link to comment Share on other sites More sharing options...
MrSpacely Posted December 25, 2005 Share Posted December 25, 2005 (edited) That sounds like the old basic(in Qbaic) way of coding;) fun Edited December 25, 2005 by MrSpacely Link to comment Share on other sites More sharing options...
Valik Posted December 25, 2005 Share Posted December 25, 2005 I suggest you stop focusing on how to do something and look more at what you want to achieve. Then you'll realize there is a partial AutoIt solution. Link to comment Share on other sites More sharing options...
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