Sign in to follow this  
Followers 0
nss

autoit crashes after the call to the c style dll succeeds

6 posts in this topic

Hello everyone,

I'm having a hard time debugging what's wrong with this.

I'm trying to call the c style library called universal speech from autoit 3 (I'm using the latest final release), and after the dll does what I want it to, autoit crashes and displays the message autoit has stopped working... I'm not sure if I'm doing something wrong here?

autoit:

#notrayicon
dllcall("UniversalSpeech.dll", "int", "speechSayA", "str", "test 123", "int", 1)
sleep(1000)

universal speech.h:

#ifndef ____UNIVERSAL_SPEECH_H__
#define ____UNIVERSAL_SPEECH_H__
#if defined __WIN32 || defined __WIN64
#define export __declspec(dllexport)
#else
#error Platform currently unsupported
#endif
#ifdef __cplusplus
extern "C" {
#endif
int export speechSayA (const char* str, int interrupt) ;
#ifdef __cplusplus
} // extern "C"
#endif
#endif

I've successfully did this in other programming languages but autoit doesn't seem to like it; plz help!

Share this post


Link to post
Share on other sites



@nss:

The C function is cdecl. 

The default calling convension of AutoIt's DllCall is stdcall.

Either change DllCall convension to cdecl (dllcall("UniversalSpeech.dll", "int:cdecl",...) (easier) or add _stdcall to your C function (you may be messing with the decorated name)


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Another route:

$oVoice = ObjCreate("SAPI.SpVoice")
$oVoice.Speak ('test 123')

And wow, I haven't used SAPI in a while...it's getting much better.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Thanks lots @binhnx.

calling with cdecl fixed it, though it'd be cool if autoit automatically tried to switch to cdecl if the stdcall one doesn't work and not just randomly crash giving anyone who's messing with dll's no idea why that happened since there can be 1 milion possible reasons.

Share this post


Link to post
Share on other sites

@nss: Simply, it's technically impossible. You cannot know the function work correctly or not until you actually call the function (and get crash). You can only check if the function is exist (name and number of parameters match), which is already handled with AutoIt


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks lots @binhnx.

calling with cdecl fixed it, though it'd be cool if autoit automatically tried to switch to cdecl if the stdcall one doesn't work and not just randomly crash giving anyone who's messing with dll's no idea why that happened since there can be 1 milion possible reasons.

Well, there's an argument to that.  You shouldn't be doing or using something you don't understand?

But more than that, if you're going to be using another libraries API, it's not too difficult to find out if it's written with STDCall or Cdecl, which alternatively narrows down the "1 million" reasons to just 1 ;).

P.S.

The help file has this information under the very function you were referencing for this post... DllCall

 

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).

Edited by SmOke_N

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.

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