Sign in to follow this  
Followers 0
Xand3r

[resolved]dll call on a custom dll

6 posts in this topic

#1 ·  Posted (edited)

i made a simple dll in visual c++ 2008 and tried to call the functions in autoit and ran into a problem :D

if i call a func with no parameters(void) it works just fine but when i pass any kind of parameters i get an error from windows saying that autoit has stopped working

os:windows vista x64 sp2

autoit:3.3.0.0

$dll = DllOpen(@ScriptDir & "\mumu.dll")
$a = 123
$s = DllCall($dll, "int", "test1")
MsgBox(0, @error, $s[0])
$s = DllCall($dll, "int", "test2","int" , 0)
MsgBox(0, @error, $s[0])

#include <stdio.h>
#define _export __declspec(dllexport)

extern "C"
{
  __declspec(dllexport) int test1(){
        return 100;
  }
  __declspec(dllexport) int test2(int z){
      return z;
  }
}

mumu.dll

Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites



you declare your functions as extern "C". So you have to use cdel in AutoIt, i think:

$s = DllCall($dll, "int:cdecl", "test2","int" , 0)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Not only that, but you need to do it like this:

#include <WinAPI.au3>
#include <Constants.au3>

;$dll = DllOpen(@ScriptDir & "\mumu.dll")

_WinAPI_LoadLibraryEx(@ScriptDir & "\mumu.dll", $DONT_RESOLVE_DLL_REFERENCES)

$a = 123
$s = DllCall(@ScriptDir & "\mumu.dll", "int:cdecl", "test1")
ConsoleWrite(@error & @CRLF)

MsgBox(0, @error, $s[0])

$s = DllCall(@ScriptDir & "\mumu.dll", "int:cdecl", "test2","int" , 5)
MsgBox(0, @error, $s[0])

Entry point is messed up. That's not good.

edit:

This example indicates that AutoIt will, if you pass string to DllCall() function, first call GetModuleHandle function and then LoadLibrary to load module.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

I think he needs also to make a .def file and specify it in the input command line of the environment compiler (Visual C++ right?) because otherwise the function's name is strange because of name decoration.

Share this post


Link to post
Share on other sites

Not only that, but you need to do it like this:

#include <WinAPI.au3>
#include <Constants.au3>

;$dll = DllOpen(@ScriptDir & "\mumu.dll")

_WinAPI_LoadLibraryEx(@ScriptDir & "\mumu.dll", $DONT_RESOLVE_DLL_REFERENCES)

$a = 123
$s = DllCall(@ScriptDir & "\mumu.dll", "int:cdecl", "test1")
ConsoleWrite(@error & @CRLF)

MsgBox(0, @error, $s[0])

$s = DllCall(@ScriptDir & "\mumu.dll", "int:cdecl", "test2","int" , 5)
MsgBox(0, @error, $s[0])

Entry point is messed up. That's not good.

tnx alot guys

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites

You are marking this as [resolved], but DONT_RESOLVE shouldn't be considered as a real resolver.

Resolving this requires of you to resolve it on a different level. There could be more people with similar unresolved problems and they could try to resolve it like it's resolved here and that would likely create new unresolved... things.

I could use "resolve" couple of times more in this post but I won't.


♡♡♡

.

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