nmontec Posted January 4, 2010 Posted January 4, 2010 Dear All, I wrote a C function in a DLL: int GetElbrusStatus(char *statuspath) I already tested the code within C and it's working. Then I created a small script to test it with AutoIT: $libreria="C:\\tmp\\libAstroDirector.dll" if FileExists($libreria) Then MsgBox(0,"Risultato","DLL found") $dll = DllOpen($libreria) if $dll<>-1 Then MsgBox(0,"Risultato","DLL Opened") $result = DllCall($dll, "int", "GetElbrusStatus", "str*","D:\\Elbrus\\Images\\elbrus.sta") MsgBox(0,"Risultato",@error) DllClose($dll) Else MsgBox(0,"Risultato","Unable to open DLL") EndIf Else MsgBox(0,"Risultato","DLL NOT found") EndIf Exit The pop up messages "DLL found" and "DLL Opened" do pop up, but after that nothing happens, I can't even get the message with the @error variable printed. What's the problem in your opinion? How can I solve this? Thanks very much for your help Best regards Nicola
Juvigy Posted January 4, 2010 Posted January 4, 2010 (edited) In a glance i see that : "D:\\Elbrus\\Images\\elbrus.sta" - this has too many slashes Maybe need to be changed to "D:\Elbrus\Images\elbrus.sta" edit: C:\\tmp\\libAstroDirector.dll - this too seems to have too many slashes Edited January 4, 2010 by Juvigy
nmontec Posted January 4, 2010 Author Posted January 4, 2010 Juvigy: getting rid of the double slashes does not solve the issue trancexx: the asterisk is needed AFAIK because you need to specify that is a pointer to a string, I used this as reference: http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm However, I tried without the asterisk and it's not working either.
trancexx Posted January 4, 2010 Posted January 4, 2010 (edited) Juvigy: getting rid of the double slashes does not solve the issue trancexx: the asterisk is needed AFAIK because you need to specify that is a pointer to a string, I used this as reference: http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm However, I tried without the asterisk and it's not working either. str is pointer, believe me. Replace this line: $result = DllCall($dll, "int", "GetElbrusStatus", "str*","D:\\Elbrus\\Images\\elbrus.sta") with this one: $result = DllCall($dll, "int:cdecl", "GetElbrusStatus", "str","D:\Elbrus\Images\elbrus.sta") Edited January 4, 2010 by trancexx ♡♡♡ . eMyvnE
nmontec Posted January 4, 2010 Author Posted January 4, 2010 str is pointer, believe me. Replace this line: $result = DllCall($dll, "int", "GetElbrusStatus", "str*","D:\\Elbrus\\Images\\elbrus.sta") with this one: $result = DllCall($dll, "int:cdecl", "GetElbrusStatus", "str","D:\Elbrus\Images\elbrus.sta") It works! Thanks a lot! By the way, reading the documentation it says: "By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type." What does cdecl mean? Which is the difference between the two calling methods and why a C compiled function needs to use cdecl? Thanks again! Nicola
monoceres Posted January 4, 2010 Posted January 4, 2010 It works! Thanks a lot!By the way, reading the documentation it says: "By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type." What does cdecl mean? Which is the difference between the two calling methods and why a C compiled function needs to use cdecl?Thanks again!Nicolastdcall and cdecl are different set of rules that defines how the stack will be managed during a function call. In short, in stdcall the callee takes care of aligning the stack while in cdecl the caller have that job. Sometimes stdcall is better, sometimes cdecl, most often stdcall. Broken link? PM me and I'll send you the file!
nmontec Posted January 4, 2010 Author Posted January 4, 2010 stdcall and cdecl are different set of rules that defines how the stack will be managed during a function call. In short, in stdcall the callee takes care of aligning the stack while in cdecl the caller have that job. Sometimes stdcall is better, sometimes cdecl, most often stdcall.Do you mean there is no rule of thumb on which one to use, without actually trying them out?
trancexx Posted January 4, 2010 Posted January 4, 2010 Every function that is meant to be used by others is (should be) followed by a proper documentation explaining the way that function is meant to be called. If you wrote the function and don't know what calling convention should be used then there's a problem. ♡♡♡ . eMyvnE
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