Jump to content

Recommended Posts

Posted

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.

Posted (edited)

whud like to see the code for that dll

newer 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 by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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.

 
Posted

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 ?

Posted

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.

Posted (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 by jaberwacky
Posted

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.

Posted

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. 

Posted (edited)

im not buying matlab coz (when i run autoit in 64-bit ofc  :P) i dont have mclmcrrt8_1.dll 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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.

 
Posted

im not buying matlab coz (when i run autoit in 64-bit ofc  :P) 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!

Posted (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 by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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.

 
Posted (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 by trancexx

♡♡♡

.

eMyvnE

Posted

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?

Posted

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.

Posted

Where did you get this error?

in scite console

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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.

 
Posted (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 by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

 

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!?

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...