Creating a DLL file and use it with System Modeler

Hello,

I can’t manage to create a DLL containing a basic function and use it in a System Modeler Model. Could somebody help me to identify what’s wrong with the following procedure ?

I wrote inside a “FunctionsDLL.c” file a unique basic function “ RhoH2O_Temp_DLL “, calculating the water volumic mass from temperature:

I did compile this file using the “x64 Native Tools Command Prompt” in my Visual Studio 2022 menu below (I don’t have the IDE):

With the command: cl.exe /LD FunctionsDLL.c

The dll file is created in the rigth directory.

I wrote in my System Modeler library a function calling the dll file:

And when I simulate the class I have the following error :

Thanks for your help,
Alexandre

You never mentioned an exports file and the definition of RhoH2OTempDLL does not start with extern "C" __declspec(dllexport). Seeing that symbols are hidden by default on Windows, that would be the first thing I would verify.

Dear Ian,

Following your answer as well as with informations from Ankit and ChatGPT I could have something working! Thanks for your help.

I share what I did below :

I worked with 2 elementary “add” and “subtract” functions.

example.c code :

example.h code :

Then to compile I used the x64 native tool command prompt of Visual studio 2022 with the following command :

cl /LD example.c /Fe:example.dll /DDLL_EXPORT

Modelica function code :

For some reason that I don’t understand I had to write the full path for the .h file. It didn’t work with the “modelica://” shortcut…