Jump to content
Sign in to follow this  
CoderDunn

Calling a DLL I write in VC++

Recommended Posts

CoderDunn

I'm taking an intermediate C++ course in college, and I'm wondering how to write a DLL that can be called within AutoIt3. I tried to make a very simple dll with a function that adds two integers, however when I try to call it from within AutoIt, the script either locks up or throws an error 3 ("function" not found in the DLL file). I was able to compile an AutoIt plugin that worked fine, but I can't get a standard DLL to work ...

Here is the dll (test dll.cpp):

__declspec(dllexport) int TestFunc(int x, int y)
{
    return x + y;
}

And here is the script:

$dll = DllOpen("Test DLL.dll")
if (@error) Then FatalError("Unable to open DLL")

$result = DllCall($dll, "int", "TestFunc", "int", 3, "int", 4)
if (@error) Then FatalError("Error calling DLL: " & @error)

MsgBox(0, "Result", $result[0])

Func FatalError($msg)
    MsgBox(0, "Fatal Error", $msg)
    Exit
EndFunc

Any help would be much appreciated. Thanks, Andy

Edited by CoderDunn

Share this post


Link to post
Share on other sites
wraithdu

What calling convention are you using in your project settings? If cdecl, then your second argument to DllCall has to be "<return_type>:cdecl".

Share this post


Link to post
Share on other sites
CoderDunn

What calling convention are you using in your project settings? If cdecl, then your second argument to DllCall has to be "<return_type>:cdecl".

I figured it out, thanks! I changed the function to use a stdcall and a .def file to export the function, and now it works :idea:

int _stdcall TestFunc(int x, int y)
{
    return x + y;
}
Edited by CoderDunn

Share this post


Link to post
Share on other sites
Rajucm

me too still facing same problem ;)

It will be great help

If you can post your vc++ dll source code..

Edited by Rajucm

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.