E1M1 Posted December 23, 2009 Share Posted December 23, 2009 (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 December 23, 2009 by E1M1 edited Link to comment Share on other sites More sharing options...
Authenticity Posted December 23, 2009 Share Posted December 23, 2009 The return value is an array type so you need to access it as so. Index 0 is the return value on success. Link to comment Share on other sites More sharing options...
E1M1 Posted December 23, 2009 Author Share Posted December 23, 2009 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 Link to comment Share on other sites More sharing options...
Authenticity Posted December 23, 2009 Share Posted December 23, 2009 (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 December 23, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Andreik Posted December 23, 2009 Share Posted December 23, 2009 You use extern "C" so you must call "type:cdecl". When the words fail... music speaks. Link to comment Share on other sites More sharing options...
E1M1 Posted December 23, 2009 Author Share Posted December 23, 2009 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 Link to comment Share on other sites More sharing options...
Authenticity Posted December 23, 2009 Share Posted December 23, 2009 Again, according to your C code, the function name is sum not sub. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now