Jump to content

Autoitv3 crashes when i call dllopen


Recommended Posts

Hi, i'm not really sure what the problem is but when i try to call a function in a DLL i made the program crashes. i'm assuming i'm trying to access some memory i don't "own". however, my dll is in the same directory as the script and i have succesfully used the dll function in a C program for testing purposes. i've attached my code any help would be appreciated.

;attempt to call and use a function from a Dll

;open the dll so we can call the function returns -1 on failure
;crases when i just call it add, but if i call it libadd it tells me it can't open it something wrong with dll itself
$dll = DllOpen("add.dll")
If $dll = -1 Then
    MsgBox(4096,"","unable to open the dll")
    Exit
EndIf

;dllcall returns and array where array[0] is the return value and the others the parameters passed
$num = DllCall($dll,"int","add","int",3,"int",4)

;print out the return value
MsgBox(0,"", &$num[0])
DllClose($dll)
Exit
Link to comment
Share on other sites

Welcome! Mayb need indicate full path to add.dll e.g $dll = DllOpen(@ScriptDir & "\add.dll") and what *.dll you trying to use?

Thanks for your reply.

the @script macro still gave me an error but i copied and pasted the full path in the dllopen function and it seemed to work. i suppose i could always keep my dll's in a common directory.

the dll i'm trying to use is one i made to test dllcall functions. it just adds two ints to together.

Link to comment
Share on other sites

Seems like dllcall is crashing autoit now

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author: bits

 Script Function:;calls a function from the add.dll to add two integers
    Template AutoIt script.

#ce ----------------------------------------------------------------------------
Const $x = 4
Const $y = 6

;open dll -1 if failure
$dll = DllOpen("C:\Documents and Settings\Tantrum\Desktop\doopsv2.5\build\dlldoops\Autoitv3 for C\lib\add.dll")
if $dll = -1 Then
    MsgBox(0,"", "ERROR: unable to open " & $dll)
    Exit
Else
    MsgBox(0,"", "SUCCESS: DLL is now opened")
EndIf


$ans = DllCall($dll,"int","add","int",$x,"int",$y)
;@eror 0 on success, 1 unable to use dll file
;if no return value:
if Not $ans[0] Then
    MsgBox(0,"DllCall Error","DllCall ERROR: " @error)
    exit
Else
    MsgBox(0,"", & $x & "+" & $y &"=" & $ans)
    Exit
EndIf

;always a good idea
DllClose($dll)
Exit

does anyone have any idea why this could be? kinda of annoying because i really liked this idea of Autoitv3

Link to comment
Share on other sites

I started using AutoIt because i thought it would be helpful in extending my C applications. however when i try to DLLCALL my program crashes. it only crashes on the dll that has the function i want though it'll just ignore any dll that doesn't have the required function. i've attached a zip file that contains the dll and C code as i'm sure the reason for this would be helpful to the Auto it team and me of course. Thanks in advance.

my auto it code that calls the dll

;open dll -1 if failure
$dll = DllOpen(FileOpenDialog("","","(*.dll)"))

if $dll = -1 Then
    MsgBox(0,"", "ERROR: unable to open " & $dll)
    Exit
Else
    MsgBox(0,"", "SUCCESS: DLL is now opened")
EndIf


$ans = DllCall($dll,"int","add","int",5,"int",4)
;@eror 0 on success,  else 1,2,3,unable to use, unknown return type, function not found in dll respectively

if @error Then
    MsgBox(0,"DllCall Error","DllCall ERROR: " & @error)
    exit
Else
    MsgBox(0,"", & $ans[0])
EndIf

;always a good idea
DllClose($dll)

ADDdll.zip

Link to comment
Share on other sites

  • Moderators

Instead of:

$ans = DllCall($dll,"int","add","int",5,"int",4)oÝ÷ ÙKjëh×6$ans = DllCall($dll,"int:cdecl","add","int",5,"int",4)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Instead of:

$ans = DllCall($dll,"int","add","int",5,"int",4)oÝ÷ ÙKjëh×6$ans = DllCall($dll,"int:cdecl","add","int",5,"int",4)
jesus christ! thank you so much for that smoke. i could have sworn i tried that before but i think i obviously didn't. can you explain what the difference is and why one works and the other doesn't. even if you can't. thank you :) i can't tell you how frustrated i was getting.
Link to comment
Share on other sites

  • Moderators

jesus christ! thank you so much for that smoke. i could have sworn i tried that before but i think i obviously didn't. can you explain what the difference is and why one works and the other doesn't. even if you can't. thank you :) i can't tell you how frustrated i was getting.

By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type.

DllCall("SQLite.dll", "int:cdecl", "sqlite3_open", "str", $sDatabase_Filename , "long*", 0).

Some compilers compile their dlls with stdcall method others cdecl.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...