- 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.
Calling dll in protected model.
3 views (last 30 days)
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.
Jack on 30 Mar 2023
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:
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.