Jump to content
Sign in to follow this  

DllCall function crash

Recommended Posts


Hi everybody,

I've written a fonction in a dll and I've got a problem when executing the AutoIt script (crash of AutoIt interpreter).

Here the code of my DLL :





#ifdef BUILD_DLL

/* DLL export */

#define DLL_EXPORT __declspec(dllexport)


/* EXE import */

#define DLL_EXPORT __declspec(dllimport)


#include <direct.h>

#include <iostream>

using namespace std;

extern "C" {

DLL_EXPORT short multby2(short input, short *output);




extern "C" {

BOOL WINAPI DllMain(HANDLE hinst, DWORD reason, LPVOID lpReserve)


//HInst = (HINSTANCE)hinst;

//printf ("Handle de la DLL de DllMain : %d\n", (unsigned int)HInst);




printf ("Attachement de la DLL au process \n");



printf ("Déttachement de la DLL du process \n");


default :




return true;



short multby2(short input, short* output)


cout << "input = " << input << endl;

*output = 2*intput;

return 0;


dll compilation


g++ -c -DBUILD_DLL function.cxx

g++ -shared -o mydll.dll function.o -mwindows

Here the autoit script :


$dll = DllOpen("mydll.dll")

$input = 3;

$str = "short;"

$struct = DllStructCreate($str)

$result = DllCall($dll, "short", "multby2", "short", $input,"ptr",DllStructGetPtr($struct))

What I observed :


The script calls the DLL : OK but it seems to have a problem during the return to the autoit script.

Any idea ?


Share this post

Link to post
Share on other sites

There is (at least) a calling convention error:

$result = DllCall($dll, "short:cdecl", "multby2", "short", $input,"ptr",DllStructGetPtr($struct))

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
Share on other sites

Change calling method to cdecl.




Share this post

Link to post
Share on other sites

Thanks a lot jchd and trancexx

It's fine now.

I will find on the net what is the meaning of cdecl.

Have a nice day.


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