ctl3d32 Posted September 9, 2009 Share Posted September 9, 2009 (edited) Hi all! I need a little help on getting return values(more than one) from a DLL function, like in the example function bellow: double __stdcall __declspec(dllexport) quadrado(double i, double j){ double k; double l; l = i*j; k = sqrt(pow(i,2) + pow(j,2)); return k,l; } How can i get variables k and l that are being returned from the DLL? Using: $r = DllCall($dll, "double", "quadrado", "double", $i, "double", $j) Returns only one variable in $r[0]. Thanks in advance, ctl3d32 Edited September 9, 2009 by ctl3d32 Link to comment Share on other sites More sharing options...
Yashied Posted September 9, 2009 Share Posted September 9, 2009 If the function call fails then @error is set to 1. Otherwise an arrayis returned that contains the function return value and a copy of allthe parameters (including parameters that the function may havemodified when passed by reference). $return[0] = function return value $return[1] = param1 $return[2] = param2 ... $return[n] = paramnhttp://www.autoitscript.com/autoit3/docs/functions/DllCall.htm My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
ctl3d32 Posted September 9, 2009 Author Share Posted September 9, 2009 (edited) Hi, Got it working, but i don't know if it's the right solution. I have changed the DLL function, as seen bellow: void __stdcall __declspec(dllexport) quadrado(double i, double j, double& k, double& l){ l = i*j; k = sqrt(pow(i,2) + pow(j,2)); } Where k and l are the returned values i want. And the autoit code to execute the DLL function is: $i = 6 $j = 4 $m = 0 $p = 0 $dll = DllOpen(@scriptdir & "\quadrado.dll") $t = TimerInit() $r = DllCall($dll, "double", "quadrado", "double", $i, "double", $j, "double*", $m, "double*", $p) $k = TimerDiff($t) / 1000 If @error == 0 Then MsgBox(0,"No error :-)", "Returned values are:" & @CRLF & "-> " & $r[3] & @CRLF & "-> " & $r[4] & @CRLF & "It took " & StringFormat("%.6f ",$k) & "seconds") ElseIf @error == 1 Then MsgBox(0,"error", "@error = 1 unable to use the DLL file") ElseIf @error == 2 Then MsgBox(0,"error", "@error = 2 unknown 'return type'") ElseIf @error == 3 Then MsgBox(0,"error", "@error = 3 'function' not found in the DLL file") EndIf DllClose($dll) The returned values are in $r[3] and $r[4]. Is this the correct or best solution? Thanks, ctl3d32quadrado.dll Edited September 9, 2009 by ctl3d32 Link to comment Share on other sites More sharing options...
omikron48 Posted September 9, 2009 Share Posted September 9, 2009 (edited) Why do you need to call it from a dll if you can modify our dll? Why not just make a function in AutoIt? Is there some reason you need a dll? Edited September 9, 2009 by omikron48 Link to comment Share on other sites More sharing options...
ctl3d32 Posted September 9, 2009 Author Share Posted September 9, 2009 Why do you need to call it from a dll if you can modify our dll? Why not just make a function in AutoIt? Is there some reason you need a dll?I just want to understand the DllCall function to maybe use it later in a more complex DLL function that may contain more complex mathematics like matrix inversion, and so on.Just for learning purposes.Thanks,ctl3d32 Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 9, 2009 Share Posted September 9, 2009 Functions can only return one value. I have no idea what you're trying to do there. The only reason the return k,l compiled is that the comma is a valid operator. To return multiple values, you just need to pass pointers. Link to comment Share on other sites More sharing options...
ctl3d32 Posted September 9, 2009 Author Share Posted September 9, 2009 Functions can only return one value. I have no idea what you're trying to do there.The only reason the return k,l compiled is that the comma is a valid operator.To return multiple values, you just need to pass pointers.I thought i could return more than one value without the need to pass the parameters as pointers.Like: i send the values of "i" and "j", and it returns "k" and "l".I were wrong. I have to send "i" and "j", and by reference "k" and "l". The function will modify "k" and "l" with the values that i want.Then, "k" and "l" will be my returned values.Thanks,ctl3d32 Link to comment Share on other sites More sharing options...
trancexx Posted September 9, 2009 Share Posted September 9, 2009 Functions can only return one value. I have no idea what you're trying to do there.The only reason the return k,l compiled is that the comma is a valid operator.To return multiple values, you just need to pass pointers.You should really force yourself to use "Reply" button.This way you are making things more confusing. You have very nice answers, no doubt about that, but just read the whole thread to see what I mean, even if it bores you.Quote me not. ♡♡♡ . eMyvnE 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