b0x4it Posted January 17, 2014 Share Posted January 17, 2014 I have defined a simple function in Matlab: function y = test1(x) y = x+1; end Then I use deploytool and compile it to "c++ shared library" (here is the dll file: https://db.tt/tLgwv0BO) and try to call it using Autoit: #include <Array.au3> $dll = DllOpen("myproj1.dll") DllCall($dll, "none", "myproj1Initialize") $result = DllCall($dll, "dword", "mlxTest1","dword",2) If @error Then msgbox(0,"",@error) DllCall($dll, "none", "myproj1Terminate") DllClose($dll) _ArrayDisplay($result) When I run this, it freezes and I have to kill SciTE. If I comment out calling myproj1Initialize and myproj1Terminate, then it does not freeze, but it returns the exact value I pass to the function! Any suggestion would be appreciated. Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2014 Share Posted January 17, 2014 What is your matlab code for mlxTest1 function? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
bogQ Posted January 17, 2014 Share Posted January 17, 2014 (edited) whud like to see the code for that dllnewer the less all i get on that dll is @error: 1 unable to use the DLL file on that 2 funcs, with no freeze mlxTest1 myproj1Initialize myproj1InitializeWithHandlers myproj1PrintStackTrace myproj1Terminate void __cdecl test1(int,class mwArray & __ptr64,class mwArray const & __ptr64) Edited January 17, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 All matlab code is what i attached above. When i compile test1 function, it makes the dll that has several functions in it including mlxtest1. There is no test1 function in it. I see the functions of the dll using DLL Export. Any suggestion ? Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 whud like to see the code for that dllnewer the less all i get on that dll is @error: 1 unable to use the DLL file on that 2 funcs, with no freeze mlxTest1 myproj1Initialize myproj1InitializeWithHandlers myproj1PrintStackTrace myproj1Terminate void __cdecl test1(int,class mwArray & __ptr64,class mwArray const & __ptr64) I have attached the code. It is just function test1. Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 What is your matlab code for mlxTest1 function? When i compile test1 function, it produces mlxtest1. Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2014 Share Posted January 17, 2014 Yes, thanks, I read in your above post. But you have only attached dll, not code, some folk including myself are wary of running other peoples executables. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jaberwacky Posted January 17, 2014 Share Posted January 17, 2014 (edited) I'm no expert on these matters but it looks to me like y is calling itself throwing it into an infinite loop. Edit: Does End signify the end of a function or the end of the program? Edited January 17, 2014 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 Yes, thanks, I read in your above post. But you have only attached dll, not code, some folk including myself are wary of running other peoples executables. I see, sure, i'll attach them once i get home. Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 Yes, thanks, I read in your above post. But you have only attached dll, not code, some folk including myself are wary of running other peoples executables. I have uploaded all of the folders/files produced by deploytool in matlab here: https://db.tt/EFCVegOM. It include source cpp file as well. Link to comment Share on other sites More sharing options...
bogQ Posted January 17, 2014 Share Posted January 17, 2014 (edited) im not buying matlab coz (when i run autoit in 64-bit ofc ) i dont have mclmcrrt8_1.dll Edited January 17, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 im not buying matlab coz (when i run autoit in 64-bit ofc ) i dont have mclmcrrt8_1.dll I have uploaded the mclmcrrt8_1.dll on my system here: https://db.tt/6e0U9anJ On my system the function (mlxTest1) just returns whatever I pass to it, which is not correct! Link to comment Share on other sites More sharing options...
bogQ Posted January 17, 2014 Share Posted January 17, 2014 (edited) when i run your code (form your first post) array[0] returns 4142669056 as return value, no crashes happend. is the return data correct? think it shud return number 3? 2+1 = 3 i guess :/ edit: hmm and i just notice this error An Error has occurred while trying to initialize the MCR. libmat.dll Error: The specified module could not be found... pff trancexx if you read this do you maybe know what was the name of that tool that was searching for dll dependency? Edited January 17, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
trancexx Posted January 17, 2014 Share Posted January 17, 2014 (edited) Yes I am, google "dependency walker". But there are also AutoIt scripts written for that in examples forum. @b0x4it, try building your dll not to have (external) runtime dependencies. If you use Visual Studio then in project properties select /MT for Runtime Library. It's under C/C++ -> Code generation. Edited January 17, 2014 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 when i run your code (form your first post) array[0] returns 4142669056 as return value, no crashes happend. is the return data correct? think it shud return number 3? 2+1 = 3 i guess :/ edit: hmm and i just notice this error An Error has occurred while trying to initialize the MCR. libmat.dll Error: The specified module could not be found... pff trancexx if you read this do you maybe know what was the name of that tool that was searching for dll dependency? Where did you get this error? Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 Yes I am, google "dependency walker". But there are also AutoIt scripts written for that in examples forum. @b0x4it, try building your dll not to have (external) runtime dependencies. If you use Visual Studio then in project properties select /MT for Runtime Library. It's under C/C++ -> Code generation. I use Matlab and the function is very simple with no dependencies. It uses Matlab Compiler (http://www-rohan.sdsu.edu/doc/matlab/toolbox/compiler/mcc.html). I have uploaded the log file in case you can get anything out of it https://db.tt/EP5ohIF0. It finishes successfully without any error. I also tried the this compiler to make executable which works perfectly. Link to comment Share on other sites More sharing options...
bogQ Posted January 17, 2014 Share Posted January 17, 2014 Where did you get this error?in scite console TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 in scite console I am not getting any error for this: #include <Array.au3> $dll = DllOpen("c:\Users\LTW530\Desktop\temp\myproj1\distrib\myproj1.dll") msgbox(0,"","$dll: " & $dll) $result = DllCall($dll, "dword", "mlxTest1","dword",10) If @error Then msgbox(0,"",@error) DllClose($dll) _ArrayDisplay($result) it does not freeze any-more, but it shows 4157414656 and 10 which is incorrect! Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2014 Share Posted January 17, 2014 (edited) Here is your function body. bool MW_CALL_CONV mlxTest1(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) { return mclFeval(_mcr_inst, "test1", nlhs, plhs, nrhs, prhs); } Something in your call appears to be missing, unless matlab dlls are different from other C/++ dlls. EDIT: Actually here's another one it could be. void MW_CALL_CONV test1(int nargout, mwArray& y, const mwArray& x) { mclcppMlfFeval(_mcr_inst, "test1", nargout, 1, 1, &y, &x); } Edited January 17, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
b0x4it Posted January 17, 2014 Author Share Posted January 17, 2014 Here is your function body. bool MW_CALL_CONV mlxTest1(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) { return mclFeval(_mcr_inst, "test1", nlhs, plhs, nrhs, prhs); } Something in your call appears to be missing, unless matlab dlls are different from other C/++ dlls. EDIT: Actually here's another one it could be. void MW_CALL_CONV test1(int nargout, mwArray& y, const mwArray& x) { mclcppMlfFeval(_mcr_inst, "test1", nargout, 1, 1, &y, &x); } I changed my matlab function to: function y = test1(x) y = sin(x); Now when I compile it in Matlab, sin() function is not used in any of the generated files. So I am guessing that using deploytool in matlab does not convert the matlab function to cpp and it just wrap it into a dll file. It means that we should not look into the cpp file, am I right? If so, then I should just find the right way to call matlab generated dlls correctly!? 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