DesireDenied Posted June 7, 2007 Share Posted June 7, 2007 i am having some difficulties on calling my own functions from my own dll. this example is simpliest as i can imagine but still - doesn't work for me, why? i'am using here dev-cpp dll template (pure dll template as you can see, empty body of some dll class constructor/destructor is not even removed but think we can ignore it) expandcollapse popup/* this is dllmain.cpp file */ /* Replace "dll.h" with the name of your header */ #include "dll.h" #include <windows.h> DllClass::DllClass() { } DllClass::~DllClass() { } BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */, DWORD reason /* Reason this function is being called. */, LPVOID reserved /* Not used. */) { switch(reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } /* Returns TRUE on success, FALSE on failure */ return TRUE; } /* myAdd function */ int myAdd (int value1, int value2) { return value1+value2; } /* myPow function */ double myPow (double value) { return value*value; } /* this is dll.h file */ #ifndef _DLL_H_ #define _DLL_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ class DLLIMPORT DllClass { public: DllClass(); virtual ~DllClass(void); private: }; extern "C" { int DLLIMPORT myAdd(int value1, int value2); } extern "C" { double DLLIMPORT myPow(double value); } #endif /* _DLL_H_ */ and at last, this is my autoit code. expandcollapse popup;~ test.au3 file #include <A3LLibrary.au3> $result=MyAdd(5,3) MsgBox('','My.dll::MyAdd',$result,1) $result=MyPow(6) MsgBox('','My.dll::MyPow',$result,1) $result=MyAdd(5,3,1) MsgBox('','My.dll::MyAdd, Method=1',$result,1) $result=MyPow(6,1) MsgBox('','My.dll::MyPow, Method=1',$result,1) Func MyAdd($value1, $value2,$Method=0) Local $AddResult $AddResult = DllStructCreate('int AddResult') If $Method=0 Then $dll = DllOpen('my.dll') Else $dll = _API_LoadLibrary('my.dll') EndIf $AddResult = DllCall($dll,'int','myAdd','int',$value1,'int',$value2) Return $AddResult DllClose($dll) EndFunc Func MyPow($value,$Method=0) Local $PowResult $PowResult = DllStructCreate('double PowResult') If $Method=0 Then $dll = DllOpen('my.dll') Else $dll = _API_LoadLibrary('my.dll') EndIf $PowResult = DllCall($dll,'double','myAdd','double',$value) Return $PowResult DllClose($dll) EndFunc my code always return 0 and this is not a good sign i supose... can't figure out why it is like that. Link to comment Share on other sites More sharing options...
piccaso Posted June 7, 2007 Share Posted June 7, 2007 try DllOpen instead of _API_LoadLibrary at least last time i checked the docs dllcall didnt support real dll handles only the pseudo handles from DllOpen() CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
piccaso Posted June 7, 2007 Share Posted June 7, 2007 (edited) and there is no double type in dllcall (at least not jet)you have to do it like Paul did hereyou also forgot :cdeclthis one works:$hDll = DllOpen("test.dll") $result = DllCall($hDll,"int:cdecl","myAdd","int",1,"int",2) ConsoleWrite("1+2=" & $result[0] & @CRLF) Edited June 7, 2007 by piccaso CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
DesireDenied Posted June 7, 2007 Author Share Posted June 7, 2007 (edited) THANKS for respond. DllOpen isn't helping me at all, already tried this is that way ($Method=0/1 in my func) with no satisfying results. im not so skilled on c++, and hope i didn't missed anything really important in this example (making such a simple dll / calling my dll functions from autoit) but something must be wrong in here if this code doesn't want to work even if i checked everything number of times. EDITED: woah, finally it works! thanks for helping me solve the.... that would be a lie lol. thanks for solving my problem Edited June 7, 2007 by DesireDenied Link to comment Share on other sites More sharing options...
piccaso Posted June 7, 2007 Share Posted June 7, 2007 (edited) did you read my second repy? i dont know how much about double but this way you can use float: void myPow (float *value) { *value = *value * *value; }$float = DllStructCreate("float") DllStructSetData($float,1,5) $x = DllCall("test.dll","none:cdecl","myPow","ptr",DllStructGetPtr($float)) ConsoleWrite(DllStructGetData($float,1) & @CRLF) edit: ok you did read it Edited June 7, 2007 by piccaso CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
DesireDenied Posted June 7, 2007 Author Share Posted June 7, 2007 of course i did Link to comment Share on other sites More sharing options...
Ramnath Posted October 20, 2008 Share Posted October 20, 2008 Hi All, I need solution for the same problem. Could please send me if you found out already? Thanks Ramnath Link to comment Share on other sites More sharing options...
Ramnath Posted October 20, 2008 Share Posted October 20, 2008 Hi All, I need solution for the same problem. Could please send me if you found out already? Thanks Ramnath Link to comment Share on other sites More sharing options...
BrettF Posted October 20, 2008 Share Posted October 20, 2008 Stop spamming this topic. Go back to your own posted topic, and wait there for a reply. Thanks, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! 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