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

3 visualizaciones (últimos 30 días)
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 comentario
sangeet pillai
sangeet pillai el 24 de En. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Benjamin Kraus
Benjamin Kraus el 27 de En. de 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 comentario
sangeet pillai
sangeet pillai el 30 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (2)

Benjamin Kraus
Benjamin Kraus el 24 de En. de 2017
Editada: Benjamin Kraus el 24 de En. de 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 comentarios
sangeet pillai
sangeet pillai el 24 de En. de 2017
Editada: sangeet pillai el 24 de En. de 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 el 27 de En. de 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.

Iniciar sesión para comentar.


sangeet pillai
sangeet pillai el 6 de Feb. de 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

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by