Sign in to follow this  
Followers 0
jonny1234

Pass an array of structures to DllCall?

5 posts in this topic

Hi,

I am trying to call a DLL function which requires an array of 16 elements to be passed to it, where each element is a structure.

There are 6 members in each structure, all of which are char[255]. I know the DLL function works because I can call it from C, by passing a pointer to the first element of the predefined array.

In AutoIt, I have tried doing (something like):

$struct_types = "char[255];char[255];char[255];char[255];char[255];char[255]"

Dim $a[16]

For $i = 0 to 15

$a[$i] = DllStructCreate($struct_types)

Next

$result = DllCall("utils.dll", "int", "elements_get", "ptr", DllStructGetPtr($a[0]))

MsgBox(0, "", "First member of first element: " & DllStructGetData($a[0], 1))

For $i = 0 to 15

$a[$i] = 0

Next

But it crashes saying that the memory could not be read.

Please can you tell me what I'm doing wrong.

Thanks for your time.

Regards,

Jonny

Share this post


Link to post
Share on other sites



I am trying to call a DLL function which requires an array of 16 elements to be passed to it, where each element is a structure.

AutoIt is not really interested in what he transfers. You just have to make sure it all fits into one, single structure.

In your case I would try something like the below (I can't test it, as the DLL is not available on my machine) :

$struct_types = "char[255];char[255];char[255];char[255];char[255];char[255]"
$StructDef=""
For $i = 0 to 15
  $StructDef&=$struct_types
Next
$rStruct= DllStructCreate($StructDef)

$result = DllCall("utils.dll", "int", "elements_get", "ptr", DllStructGetPtr($rStruct))

MsgBox(0, "", "First member of first element: " & DllStructGetData($rStruct, 6*0+1))
MsgBox(0, "", "Second member of sixth element: " & DllStructGetData($rStruct, 6*5+2))

$rStruct=0

Share this post


Link to post
Share on other sites

Thanks for your reply BitRot.

I see what you are doing by joining 16 structures into one big structure, but unfortunately it still crashes with the same error.

Is the joining of structures in this way equivalent to an array of structures? If so then I must be doing something wrong. I will continue to investigate. I just wanted to let you know my initial results.

Regards,

Jonny

Share this post


Link to post
Share on other sites

BitRot,

It works. There was an error in that a semi-colon needed to be added to the end of $struct_types during the building of the $StructDef string.

Thanks for your help. It is much appreciated.

Regards,

Jonny

Share this post


Link to post
Share on other sites

It works. There was an error in that a semi-colon needed to be added to the end of $struct_types during the building of the $StructDef string.

Whoops ! Sorry 'bout that. :lmao:

Thanks for your help. It is much appreciated.

You're welcome. :ph34r:

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