Sign in to follow this  
Followers 0
Infinite

Function Address/Pointer

6 posts in this topic

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;
}

Share this post


Link to post
Share on other sites



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++

Share this post


Link to post
Share on other sites

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 :P

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 :P

Edited by Infinite

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

That sounds like the old basic(in Qbaic) way of coding;) fun

Edited by MrSpacely

Share this post


Link to post
Share on other sites

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.

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