Kris123 Posted February 16, 2009 Posted February 16, 2009 Hi, How to pass an array to a function by reference and how to get the array elements. Thanks in advance.
JRowe Posted February 16, 2009 Posted February 16, 2009 Check out the help file, http://www.autoitscript.com/autoit3/docs/keywords/Func.htmIt denotes exactly how you can use ByRef to pass your array by reference.Good luck [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Kris123 Posted February 16, 2009 Author Posted February 16, 2009 I saw this help in AutoIT. But i want how to deal with arrays. Thanks.
JRowe Posted February 16, 2009 Posted February 16, 2009 Dim $MyArray[2] ;When using ByRef keyword, you're just passing a reference to the function and manipulating the actual array created earlier. Blah($MyArray) MsgBox(0, $MyArray[0], $MyArray[1]) Func Blah(ByRef $MyArrayRef) Local $Dali = 2 $MyArrayRef[0] = "Hello" $MyArrayRef[1] = $Dali EndFunc [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Kris123 Posted February 16, 2009 Author Posted February 16, 2009 Thanks for your reply. But here in my script, i should send an array and also array length (both are by reference)to an API which is exposed in a DLL. Thanks.
JRowe Posted February 16, 2009 Posted February 16, 2009 Ok, I recommend you post all your relevant code, and elaborate exactly what you want. This piecemeal approach to getting help isn't going anywhere. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Kris123 Posted February 16, 2009 Author Posted February 16, 2009 Here i am passing an array and it's lenth to an API in DLL $Str = "long $Length;char $Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Length) $b = DllStructCreate($Nonarray) DllStructSetData($a, 1, 0) DllStructSetData($b, 1, "", 0) $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetPtr($b, 1)) After executing this, AUTO IT is stops executing.
JRowe Posted February 16, 2009 Posted February 16, 2009 Someone else will have to jump in on this one. Also, what dll are you calling, what function are you calling from the dll, and what are you trying to do with your code. Again, post ALL relevant code (and put it in tags.) Explain what you want. Don't just post "AutoIt stops executing." Without that, you might as well be asking how many fingers you're holding up. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Kris123 Posted February 16, 2009 Author Posted February 16, 2009 Here i am trying to pass an array and length of array to a function. My interest is after passing the array and length as reference, i need to to get the array and i have to process the values in it. The function witch will return the array elements is exposed in a DLL. This i am calling in my script. Protocol_GetNonConValues($MONITOR_COLOR_PRESET, $arrlen, $Nonarr)Actual function is in header file.Func Protocol_GetNonConValues($opcode, ByRef $Length, Byref $Nonarray) $Str = "long $Length;char $Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Length) $b = DllStructCreate($Nonarray) DllStructSetData($a, 1, 0) DllStructSetData($b, 1, "", 0) $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetPtr($b, 1)) msgbox(0, "", $Result[2]) msgbox(0, "", $Result[3]) EndFuncMonitor_GetSupportedNCValues: this function will return the array of noncontinuous values and its length.
Manjish Posted February 16, 2009 Posted February 16, 2009 Like this?? #include<array.au3> dim $avArray[10] $avArray[0] = "JPM" $avArray[1] = "Holger" $avArray[2] = "Jon" $avArray[3] = "Larry" $avArray[4] = "Jeremy" $avArray[5] = "Valik" $avArray[6] = "Cyberslug" $avArray[7] = "Nutster" $avArray[8] = "JdeB" $avArray[9] = "Tylo" $str=_ArrayToString($avArray,"|") $arr=StringSplit($str,"|") array($arr[0],$avArray) Func array($length,$array) _ArrayDisplay($array,"") msgbox(4096,"","dimensions: "& $length) EndFunc [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
PsaltyDS Posted February 16, 2009 Posted February 16, 2009 Srikrishna said: Here i am trying to pass an array and length of array to a function. My interest is after passing the array and length as reference, i need to to get the array and i have to process the values in it. The function witch will return the array elements is exposed in a DLL. This i am calling in my script. Protocol_GetNonConValues($MONITOR_COLOR_PRESET, $arrlen, $Nonarr) Actual function is in header file. Func Protocol_GetNonConValues($opcode, ByRef $Length, Byref $Nonarray) $Str = "long $Length;char $Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Length) $b = DllStructCreate($Nonarray) DllStructSetData($a, 1, 0) DllStructSetData($b, 1, "", 0) $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetPtr($a, 2)) msgbox(0, "", $Result[2]) msgbox(0, "", $Result[3]) EndFunc Monitor_GetSupportedNCValues: this function will return the array of noncontinuous values and its length There is some real confusion in there. The dollar sign "$" indicating an AutoIt variable is not appropriate for DLL struct element name, so $Str should look like this: $Str = "long Length;char Nonarray[128]" Then, you fail to use $Str to define your struct at all. That should be just: $a = DLLStructCreate($Str) A DLL struct array of char type is just a string variable in AutoIt and is not passed as an AutoIt array. After all that it is so confusing I lost track of what you wanted to do in the first place... 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
Kris123 Posted February 18, 2009 Author Posted February 18, 2009 Hi Thanks for your reply. I have tried in the same way, but when i execute the DllCall, AutoIt is stops executing. Func Protocol_GetNonConValues($opcode, $Length, $Nonarray) $Str = "long Length;char Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Str) DllStructSetData($a, 1, 0) DllStructSetData($a, 2, "", 0) MsgBox(0, "", "hello") $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetData($a, 2)) msgbox(0, "", $Result[2]) msgbox(0, "", $Result[3]) EndFunc My Problem is how to get the array returned by the function Monitor_GetSupportedNCValues.
trancexx Posted February 18, 2009 Posted February 18, 2009 Srikrishna said: Hi Thanks for your reply. I have tried in the same way, but when i execute the DllCall, AutoIt is stops executing. Func Protocol_GetNonConValues($opcode, $Length, $Nonarray) $Str = "long Length;char Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Str) DllStructSetData($a, 1, 0) DllStructSetData($a, 2, "", 0) MsgBox(0, "", "hello") $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetData($a, 2)) msgbox(0, "", $Result[2]) msgbox(0, "", $Result[3]) EndFunc My Problem is how to get the array returned by the function Monitor_GetSupportedNCValues.You need to post description of that function, description of parameters, description of required structure(s). There are like zillion possible scenarios regarding informations that you provided. More is needed if you want someone to help you with that. ♡♡♡ . eMyvnE
Kris123 Posted February 19, 2009 Author Posted February 19, 2009 Func Protocol_GetNonConValues($opcode, $Length, $Nonarray) $Str = "long Length;char Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Str) DllStructSetData($a, 1, 0) DllStructSetData($a, 2, "", 0) MsgBox(0, "", "hello") $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetData($a, 2)) msgbox(0, "", $Result[2]) msgbox(0, "", $Result[3]) EndFuncfunction i am calling as Protocol_GetNonConValues($MONITOR_COLOR_PRESET, $arrlen, $Nonarr)This function internally invokes DllCall where the API inside that Monitor_GetSupportedNCValues will return array and it's length.so we have to pass the array and arraylengh as passbyreference to the function. I think so this clarifies.
cherdeg Posted February 19, 2009 Posted February 19, 2009 (edited) Srikrishna said: blah Hey WTF, man??? Sorry for being rude, but by only reading this thread I got upset. Already in the almost 1st answer you have been asked to talk about what you are trying to do. "Passing an array to a function by ref" is not, I repeat NOT an answer to this question (and this won't change, no matter how often you post the same code again). If you are here in need for qualified answers (which the ppl here usually are very willing to give), tell us about your script and what it is about. If for some reason you don't want to post your whole script, at least wrap up your function to do something so we can see what it is supposed to do. Again, sorry thousandfold for being rude. I will do some massive penance now ("Dear Lord...blah...blub...blah...please forgive...blah...blub...blah...please punish...blah...blub...blah..."). Edited February 19, 2009 by cherdeg
trancexx Posted February 19, 2009 Posted February 19, 2009 Srikrishna said: Func Protocol_GetNonConValues($opcode, $Length, $Nonarray) $Str = "long Length;char Nonarray[128]" ;Creating a Structure $a = DllStructCreate($Str) DllStructSetData($a, 1, 0) DllStructSetData($a, 2, "", 0) MsgBox(0, "", "hello") $Result = DllCall($PE_Plugin, "long", "Monitor_GetSupportedNCValues", "long", $opcode, "long*", DllStructGetPtr($a, 1), "long*", DllStructGetData($a, 2)) msgbox(0, "", $Result[2]) msgbox(0, "", $Result[3]) EndFunc function i am calling as Protocol_GetNonConValues($MONITOR_COLOR_PRESET, $arrlen, $Nonarr) This function internally invokes DllCall where the API inside that Monitor_GetSupportedNCValues will return array and it's length. so we have to pass the array and arraylengh as passbyreference to the function. I think so this clarifies.I didn't meant description of your function, but description of Monitor_GetSupportedNCValues function and its parameters. Btw, you probably need pointer to created structure there somewhere, not only one element. And if the element of structure is an array then its first element is 1 (not 0). Just post description. ♡♡♡ . eMyvnE
Kris123 Posted February 20, 2009 Author Posted February 20, 2009 The description of function is : long Monitor_GetSupportedNCValues (long lnCommand, long* o_plNCValueCount, long* o_larrNCValues)
trancexx Posted February 20, 2009 Posted February 20, 2009 Srikrishna said: The description of function is :long Monitor_GetSupportedNCValues (longlnCommand, long* o_plNCValueCount, long* o_larrNCValues)Bill's mother is making a cake. Says to him: "Son, go to the store and buy me 10 eggs. If there would be those little butters - buy 2". Bill goes.After like 10 minutes Bill comes home with 2 eggs.More is needed Srikrishna. ♡♡♡ . eMyvnE
Kris123 Posted February 20, 2009 Author Posted February 20, 2009 Monitor_GetSupportedNCValues it is an API exposed in a DLL.It will return all the noncontinues values of the required parametre.Here suppose i want to get all noncontinious values of color, (the values will be like 0, 5, 7, 8, 9, 11 etc) then send the colorname as longlnCommand and we have to get all noncontinious values into an array and it is lenght also.Now ithink so it is clear for you.
cherdeg Posted February 20, 2009 Posted February 20, 2009 Srikrishna said: tralla-la.Hey: Even if I was the one being able to help you (and I'm glad I ain't), I simply wouldn't. 18 posts (where the half of them consist of almost the same words) in a thread to come to this last answer of yours (which doesn't help either, at least not me) are an impertinence. Post your whole script or leave it (my personal opinion, but maybe you'll find somebody still willing to help).
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