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

5 次查看(过去 30 天)
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 个评论
sangeet pillai
sangeet pillai 2017-1-24
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?

请先登录,再进行评论。

采纳的回答

Benjamin Kraus
Benjamin Kraus 2017-1-27
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.

更多回答(2 个)

Benjamin Kraus
Benjamin Kraus 2017-1-24
编辑:Benjamin Kraus 2017-1-24
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 个评论
sangeet pillai
sangeet pillai 2017-1-24
编辑:sangeet pillai 2017-1-24
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 2017-1-27
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.

请先登录,再进行评论。


sangeet pillai
sangeet pillai 2017-2-6
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

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by