MATLAB Answers

Can I call a Simulink generated DLL file in a Simulink model (Matlab 2018b)?

49 views (last 30 days)
Panagiotis Bountouris
Panagiotis Bountouris on 14 Apr 2019
Commented: Ziyan Li on 27 Apr 2020
I have created a .dll file (see fig: PID_win64.dll) and associated headers (see fig: in PID_ert_shrlib_rtw) with the aid of Simulink (see fig: PID.slx). I now want to call it in a simulink model (see fig: test_dll.slx) where I am going to test it. I have read in older posts that I have to use S-Function block. Please let me know if this is the proper route I should follow and if so could you please share with me the exact steps (where should I allocate the name of dll and headers - which headers) ?
The final aim is to import the created .dll file in DIgSILENT POWERFACTORY. If anyone can share any further information regarding this would be highly appreciated.


Sebastian D.
Sebastian D. on 26 Nov 2019
Hi Panagiotis,
I have the same use case: I generated a DLL file from a Simulink model (using the System Target File "ert_shrlib.tlc"). To test the generated DLL, I want to call the DLL in another Simulink model.
I also thought about using a S-Function to include the DLL. Did you find an appropriate solution to your problem?
Many thanks in advance!
Kind regards
Ziyan Li
Ziyan Li on 27 Apr 2020
hi, i have the same quesition. Have you solved your problem? I have a DLL (compiled from visual studio), i want to know, how can i call it in Simulink. This DLL was also used in Powerfactory.

Sign in to comment.

Answers (1)

Mark McBroom
Mark McBroom on 15 Apr 2019
Yes, creating an S-Function one possible approach. I presonally prefer the legacy_code tool, but S-Function builder will also work.
Note that you can also call C code in a DLL from a MATLAB Function block using the coder.ceval() function.


Show 1 older comment
Mark McBroom
Mark McBroom on 20 Apr 2019
No particular guidelines. There are a number of examples for each approach. Tricky part for either is specifying the layout of input/output buses to the Simulink model.
An altnerate appraoch is to put your entire model into a sub-system. Then, select the subsystem and pick the following from the Simulink menu:
Code => C/C++ code => Generate S-Function
This will generate an S-Function from the subsystem. You can now use this s-function in another Simulink model.
Finally, if your goal of creating an s-function is to hide the implementation details of the model before providing to someone else, you can use the Protected Model feature.
Panagiotis Bountouris
Panagiotis Bountouris on 23 Apr 2019
Thank you Mark. The ultimate goal is to import the already generated dll to digsilent (another simulations program). Before that I wanted to import the dll in simulink, so I compare the dll with the actual model. I don't think creating an S-Function out of the initial model will help me at this stage. Correct me if I am wrong. Thank you for your help anyway!
ESSALMI YOUSSEF on 29 Nov 2019
Hi, I have the same issue, any solutions, or guidlines ? thank you in advance

Sign in to comment.

Sign in to answer this question.