Sign in to follow this  
Followers 0
E1M1

What's wrong in DLL Call?

7 posts in this topic

#1 ·  Posted (edited)

I am new to dll stuff ;) Why I see 0 in msgbox? I should see 4 there.

MsgBox(0,0,DllCall("formulas.dll","dword","sub","int",2,"int",2))

Dll

#include "stdafx.h"

#define DLL extern "C" __declspec(dllexport)

DLL WORD sum(int a,int b)
{
    return a+b;
}
Edited by E1M1

edited

Share this post


Link to post
Share on other sites



The return value is an array type so you need to access it as so. Index 0 is the return value on success.

Share this post


Link to post
Share on other sites

Is my autoit code bad or DLL?

$var = DllCall("formulas.dll","int","sub","int",2,"int",2) 
MsgBox(0,0,$var[0])

C:\Users\rain\Documents\Visual Studio 2008\Projects\formulas\Debug\dllcall.au3 (2) : ==> Subscript used with non-Array variable.:
MsgBox(0,0,$lol[0])
MsgBox(0,0,$lol^ ERROR

edited

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You didn't specify a default calling convention in your dll project right? So it's assumed to be __cdecl, try:

$var = DllCall("formulas.dll","int:cdecl","sub","int",2,"int",2)
MsgBox(0,0,$var[0])

..or specify the calling convention in the dll project:

#include "stdafx.h"

#define DLL extern "C" __declspec(dllexport)

DLL WORD WINAPI sum(int a,int <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />
{
    return a+b;
}

Edit: It's sum not sub.

$var = DllCall("formulas.dll","int:cdecl","sum","int",2,"int",2)
MsgBox(0,0,$var[0])

..and the return value is ushort not int. ;)

Edited by Authenticity

Share this post


Link to post
Share on other sites

You use extern "C" so you must call "type:cdecl".


When the words fail... music speaks

Share this post


Link to post
Share on other sites

eh what's wrong? I cant find it.

$var = DllCall("formulas.dll","int:cdecl","sub","int",2,"int",2)

DLLcall return 0 but

msgbox cause error

C:\Users\rain\Documents\Visual Studio 2008\Projects\formulas\Debug\dllcall.au3 (4) : ==> Subscript used with non-Array variable.:
MsgBox(0,0,$var[0])
MsgBox(0,0,$var^ ERROR

edited

Share this post


Link to post
Share on other sites

Again, according to your C code, the function name is sum not sub.

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