I think it might be because I am using a not in-line S-function as I am using the S-function to call the dll...
Calling dll in protected model.
3 views (last 30 days)
Show older comments
Hello,
I've been trying to call a .dll from a protected model, but it doesn't seem to be calling my function from the .dll.
I've succesfully been able to call my dll function in my Simulink block, but when I create a protected model out of this Simulink block, it seems like it doesn't call the function from the dll anymore.
I know it's not called for two reasons:
- The simulation return is wrong
- I've added a license check with a dongle to the dll and it runs even without the dongle
Is it a limitation of protected models? Is there any other way to protect this model? I don't want the user to be able to see/modify/remove this.
Thanks!
Accepted Answer
Jack
on 30 Mar 2023
Hi,
It is possible that the issue you are facing is related to the use of a non-inline S-function. Protected models have certain limitations on the types of S-functions that can be used, and non-inline S-functions may not be supported.
One solution you could try is to convert your S-function into an inline S-function, which should be compatible with protected models. To do this, you can use the S-function Builder, which is a tool provided by Simulink to create S-functions.
Here are the steps to create an inline S-function using the S-function Builder:
- Open the S-function Builder by typing sfcn in the MATLAB command window.
- Click "New" to create a new S-function.
- In the "General" tab, specify the name and location of the S-function.
- In the "Ports" tab, specify the input and output ports of the S-function.
- In the "Parameters" tab, specify any parameters that the S-function requires.
- In the "Callbacks" tab, implement the S-function's functions (such as mdlInitializeSizes, mdlInitializeSampleTimes, mdlStart, mdlOutputs, etc.) using MATLAB code.
- Save and close the S-function Builder.
Once you have created the inline S-function, you can use it in your Simulink model and protect the model using Simulink's built-in protection mechanisms.
Alternatively, you could consider encrypting your DLL using a tool such as Themida or VMProtect, which would make it more difficult for users to access and modify your DLL. However, this approach may not be foolproof, and it would not prevent users from using your DLL outside of your protected model.
2 Comments
Jack
on 30 Mar 2023
I'm glad to hear that you found a solution that works for you! Using MATLAB script and protecting it with pcode can be a good option for implementing custom functionality in Simulink while keeping your code confidential. If you have any further questions or concerns, feel free to ask.
More Answers (0)
See Also
Categories
Find more on Simulink Coder 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!