Sign in to follow this  
Followers 0
nmontec

DllCall problem

9 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Juvigy

Share this post


Link to post
Share on other sites

Remove asterisk character.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

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.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

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