Jump to content
Sign in to follow this  

Problem with DLLCall

Recommended Posts


Once more i need the help of more experienced programmers.

I've written the dll with the function like this:

void Function(char* ret, int p1, int p2) {
// messing with "ret" variable

The script that utilizes this function looks like this (ok, it's more complex, but this is the place where something goes wrong):

#Include <Misc.au3>

HotKeySet ( "!{ESC}", "Terminate" )

Global $mydll = -1
Global $card

Global $mydll = DllOpen ( @ScriptDir & "\mydll.dll" )
If ( $mydll == -1 ) Then
    MsgBox (0, "ERROR", "ERROR: can't open dll!" )

        Sleep ( 50 )
    Until ( _IsPressed ( 04 ) == 1 )
        Sleep ( 50 )
    Until ( _IsPressed ( 04 ) == 0 )

    $asdasd = "                                     "
    $dllresult = DllCall ( $mydll , "none", "Function", "str:cdecl", $asdasd ,"int:cdecl", 0, "int:cdecl", 0)
    If ( @error ) Then
        MsgBox (0, "ERROR " & @error, "Dll function call failed." )

    $asdasd = $dllresult[1] 

    While ( StringRight ($asdasd, 1) == " " OR StringRight ($asdasd, 1) == "?" )
        $asdasd = StringTrimRight ( $asdasd, 1 )

    MsgBox ( 0, "CardID", $asdasd)
Until ( 0 == -1 )

Func Terminate()
    If ( $mydll <> -1 ) Then
        DllClose ( $mydll )
    Exit 0

Basically the script should wait until the middle mouse button is clicked, execute the dll function, and then display the result (returned by reference) in message box. But no matter what i pass as the 2nd argument of DllCall i get the @error = 2, which is "unknown return type" error.

Everything worked fine with autoit v3.2.4, after update to v3.2.6 i got the "autoit detected stack corruption error", but i was able to solve this problem by just adding ":cdecl" to the parameter types (i figured out the "char*" in dll may cause the problem).

Please advise, i have no idea what am i doing wrong.


Please close this thread.

Should read more carefully: the ":cdecl" should be added only after the return type, not after the types of parameters.

Stupid me.

Edited by chalup

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.