Message Boards Message Boards

0
|
352 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Creating a DLL file and use it with System Modeler

Posted 1 month ago

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 “ RhoH2OTempDLL “, calculating the water volumic mass from temperature: enter image description here

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):

enter image description here

With the command: cl.exe /LD FunctionsDLL.c enter image description here The dll file is created in the rigth directory.

I wrote in my System Modeler library a function calling the dll file: enter image description here

And when I simulate the class I have the following error : enter image description here

Thanks for your help, Alexandre

2 Replies

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.

POSTED BY: Ian Hojnicki

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 :

enter image description here

example.h code :

enter image description here

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 : enter image description here

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...

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract