jonny1234 Posted October 3, 2006 Share Posted October 3, 2006 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 Link to comment Share on other sites More sharing options...
BitRot Posted October 3, 2006 Share Posted October 3, 2006 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 Link to comment Share on other sites More sharing options...
jonny1234 Posted October 4, 2006 Author Share Posted October 4, 2006 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 Link to comment Share on other sites More sharing options...
jonny1234 Posted October 4, 2006 Author Share Posted October 4, 2006 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 Link to comment Share on other sites More sharing options...
BitRot Posted October 4, 2006 Share Posted October 4, 2006 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. Thanks for your help. It is much appreciated.You're welcome. 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