Jump to content

Getting data from Int-array returned by DllCall


DHL
 Share

Recommended Posts

I am fairly new to C++, pointers and such so please bear with me.

I want to access data in an array of integers returned by dllCall. I have created the dll myself. The function in the dll looks like this:

DllExport int *GetMyIntegers(int id)
{
        //some unrelated checks of the int "id"
    return myIntegers;
}

Where myIntegers is an array containing some int values. The array is defined like this:

int myIntegers[1000];

My AutoIt script calls the dll like this, and I try to write a result to the console:

$intptr = DllCall("mydll.dll", "int*:cdecl", "GetMyIntegers", "int", $id)

$struct = DllStructCreate("int[1000]",$intptr[0])           
$myIntegerArray = DllStructGetData($tPtr, 1);

ConsoleWrite($myIntegerArray[0])

The output from ConsoleWrite($myIntegerArray[0]) is a number (a seven digit one), but not the same as the one in myIntegers[0] in the dll.

How can I get the correct array values from the dll to autoit?

Link to comment
Share on other sites

Where did $tPtr come from? Shouldn't that be:

$myInteger = DllStructGetData($struct, 1, 1)
ConsoleWrite("$myInteger = " & $myInteger & @LF)

:x

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
Link to comment
Share on other sites

Where did $tPtr come from? Shouldn't that be:

$myInteger = DllStructGetData($struct, 1, 1)
ConsoleWrite("$myInteger = " & $myInteger & @LF)

:x

My bad. Of course you are right. I forgot to change it when I rewrote the example code for better readability. Anyway, It works now.

$myInteger = DllStructGetData($struct, 1, 1) did the trick. Thank you!

(I am sure I tried that yesterday without any luck, but hey - it works now :P )

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