Is it possible to call functions from a DLL that was built in MATLAB? ie possibility of using matlab dll in matlab script itself.

7 views (last 30 days)
I am somewhat new to matlab.So i had a question.Incase i have a DLL that was built from a matlab code using 'deploytool'.Now i have used functions from .net dll's that i linked using 'Net.addAssembly' and 'import'.But i wanted to know if it is possible to use the dll's that were built using matlab compiler in MATLAB itself?
One use case for this maybe if someone has written a code and doesnt want to reveal it,then he/she can provide the DLL's to 3rd party.
  1 Comment
sangeet pillai
sangeet pillai on 24 Jan 2017
i tried this by creating a simple .m function(without the need to pass any input parameters and without any output.it just does some calculations and writes time to a file) and built a .net dll from it using matlab compiler.Then i tried to link it in the same way one would for a .net dll ie Net.addAssembly and import.But then when i tried calling the function,it gives error like no static method for class...Please help.I tried asking around but havent received any solution.Is it possible in the first place?

Sign in to comment.

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 27 Jan 2017
Let me propose another solution: Just P-code your MATLAB code using the pcode function and distribute the P-file to the user. If your only goal is to protect your source code, that should be sufficient, and much easier than using the MATLAB Compiler SDK. This will also eliminate any need for the user to install the MATLAB Runtime.
The MATLAB Compiler SDK is really meant for making your code available outside MATLAB, using it to obfuscate your code isn't really what it was meant for.
  1 Comment
sangeet pillai
sangeet pillai on 30 Jan 2017
Thank you very much for taking out time to answer my queries.It is very much appreciated.It helped solve my doubts.I am satisfied with the answer.

Sign in to comment.

More Answers (2)

Benjamin Kraus
Benjamin Kraus on 24 Jan 2017
Edited: Benjamin Kraus on 24 Jan 2017
I think what you need to do is to write a MEX function wrapper around your new DLL. MEX functions are the interface that allows MATLAB to call C/C++ code.
Basically, write a C/C++ function named "mexFunction", with a signature as described in that doc page. Within your C/C++ function import the DLL and call the DLL like you would in any other C/C++ code.
  2 Comments
sangeet pillai
sangeet pillai on 24 Jan 2017
Edited: sangeet pillai on 24 Jan 2017
First of all thank you very much for taking time out to answer this question.Now i want to clarify a few things.
1) Say for example i have a simple matlab function experiment.m(it doesnt need any input parameters nor gives any output.it just performs some calculations and writes some value to a .txt file)
2) Now if suppose i use MATLAB Compiler SDK and convert this matlab .m file into a .net dll using deploytool.
3) I give this dll to a 3rd party.
4) Now can he/she use this DLL in his/her Matlab script the same way they would use a DLL created from .net code(since this dll is created from matlab code)
5) I have tried using dll's with Net.addAssembly and import.So can i use the same for this particular dll?
Now please keep in mind that i dont want to use this dll in .net/c/c++ code as of now.just use it in matlab.
Benjamin Kraus
Benjamin Kraus on 27 Jan 2017
If you don't plan to use your DLL outside MATLAB than the MATLAB Compiler SDK is not really the best tool for the job, and any attempt to get it working will be kind of a hack. Based on your description, it sounds like you just want to pcode your function.

Sign in to comment.


sangeet pillai
sangeet pillai on 6 Feb 2017
It was explicitly stated on NET.addAssembly help page that it doesnt support dll's compiled using matlab compiler sdk.I accidentally came across it.I wish i had read that earlier

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!