Jump to content
Sign in to follow this  
E1M1

What's wrong in DLL Call?

Recommended Posts

E1M1

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
Authenticity

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
E1M1

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
Authenticity

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
Andreik

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
E1M1

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
Authenticity

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  

×

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.