MATLAB Answers

How to open .dll file in MATLAB. I have converted the .slx file to .dll file format. Now I want to open and see the results. I don't have any header file which I can use with the function "loadlibrary"

7 views (last 30 days)
I have .dll file which I want to open and run in MATLAB. What is the procedure, please suggest.

  0 Comments

Sign in to comment.

Accepted Answer

Kojiro Saito
Kojiro Saito on 3 Mar 2020
Edited: Kojiro Saito on 4 Mar 2020
For C shared library, you can load the dll by loadlibrary and call functions by calllib.
For detail, please see this document.
For C++ shared library, you need to do addpath in order to set your dll file to MATLAB's search path and you can call functions by clib.libname.funcname.
For detail, please see this document.
For .NET assembly, you can load the dll by NET.addAssembly and call functions by like this.
asm = NET.addAssembly('your.dll');
cls = dotNetTestClass.TestClass; % dotNetTestClass is namespace and TestClass is class in C#
a = 1; % Input 1
b = 2; % Input 2
result = TestFunc(cls, a, b); % TestFunc is function name in C#
For detail, please see this document.
If the dll is created from .slx using Embedded Coder, you need to do an additional step as described in the following answer.

  12 Comments

Show 9 older comments
Kojiro Saito
Kojiro Saito on 13 Mar 2020
@Krutika Shetkar
>Hi Kojiro,
>I have successfully loaded the dll library. Can you suggest me how to test the file like how I can run the file >and check the output in simulink/MATLAB.
As described in my first answer, libfunctions and calllib will be used for C shared dll. It depends on your model, but you can find which functions should be called by the following.
libfunctions('controller_win64')
or,
libfunctionsview 'controller_win64'
Possibly, controller_win64_initialize, controller_win64_terminate and controller_win64_step will be found.
You can call these functions by
calllib('controller_win64', 'controller_win64_initialize')
calllib('controller_win64', 'controller_win64_step')
calllib('controller_win64', 'controller_win64_terminate')
I'm not sure your controller model, but if your model requires some input, you need to add input arguments in calllib like, calllib('controller_win64', 'controller_win64_step', input1, input2, ...).
For detail, please read the following documents.
Krutika  Shetkar
Krutika Shetkar on 18 Mar 2020
Hi Kojiro,
Is there any solution where I can run the dll file in simulink? Can you suggest me how to run the dll file in simulink to check the results.

Sign in to comment.

More Answers (1)

Krutika  Shetkar
Krutika Shetkar on 12 Mar 2020
Hi Kojiro,
I have successfully loaded the dll library. Can you suggest me how to test the file like how I can run the file and check the output in simulink/MATLAB.

  0 Comments

Sign in to comment.


Translated by