question

Axel Kohonen avatar image
3 Likes"
Axel Kohonen asked anthony.johnson edited

Changes in returning a string from a dll in FlexSim 2017?

Hi,

We have a dll that returns a string from a custom dll built with the dll-maker project that has worked fine until now changing to the FlexSim 2017 version. The .zip file is attached that contains the dll code and the model file that I use to use the dll.

I am trying to follow the instructions here but I cannot get it to work. The code in the dll is the following

and the code in the model just uses a simple .dll linked user command that is defined to return a Variant data type. The dll linked function writes to the output console in FlexSim, but I cannot get the returned string into FlexSim. I get the exception seen in the System console in the image below.

Any clue on what is happening here?

Thank you!

Kind regards,

Axel

FlexSim 17.0.0
dll makerdll functions
dllcode.jpg (18.5 KiB)
modelview.jpg (102.3 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
anthony.johnson avatar image
4 Likes"
anthony.johnson answered anthony.johnson edited

These problems are quite often caused because of mismatches in the header files, which is the case here. Specifically, with 2017 we made several changes to the Variant class, such that if you have a 2016 header defining Variant (datatypes.h), it will not return correctly because the 2016 Variant is different than the 2017 Variant.

Obviously, we can do a better job of keeping the dll maker repository up to date. However, you can usually fix this on your own without having to wait for us to update the dll maker repository. The way I usually do it is by doing a diff analysis on my project's headers relative to the headers in the installed version. I use WinMerge, and I compare my project directory with <FlexSim-Install-Directory>\program\system\include\. I don't move any new headers into my dll project. I only copy existing headers with differences to my dll project.

When we initially made the dll maker repository available, we made it with the idea that it would be forward-compatible with future versions. Unfortunately, that is no longer the case, specifically because functions can now return Variant, a non-primitive class that may need tweaks and changes over time. In my opinion the ability to return a Variant, and with that arrays, strings, nodes, etc., outweighs the downside of having to update headers. Perhaps Variant changes will settle over time such that header updates are not required as often. However, for now we advise you to update headers at least with each feature release of FlexSim.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anthony.johnson avatar image anthony.johnson ♦♦ commented ·

As a side note, with the release of FlexSim 2017, FlexScript is now compiled to machine code. Thus if the main reason you are using a dll is for execution speed, the improvement you get will now be marginal at best. The reasons I can still see for integrating with dll code would be, first, if you want to integrate with C++-specific or third party functionality, or second, if you want to protect intellectual property. Also, in some cases people prefer the visual studio environment for debugging. However, FlexScript got a pretty substantive upgrade with 2017 such that it is no longer easily swappable with c++ (at least, if you use the new dot syntax features). Anyway, those are just a few things to consider in deciding to use dlls.

3 Likes 3 ·
Axel Kohonen avatar image Axel Kohonen anthony.johnson ♦♦ commented ·

Hi @anthony.johnson

We are using the .dll functions to read and write to files and as far as I know the built-in FlexSim functions fileopen/fileread etc. cannot handle multiple file pointers at the same time while we want to write to multiple report files.

Please correct me if I am wrong or if one can circumvent this somehow in a good way. I assume that the opening and closing files for reading/writing every time that we want to write a line to the file induces some overhead compared to just opening once and closing when the model run is done. Am I right?

Thank you!

Kind regards,

Axel

0 Likes 0 ·
anthony.johnson avatar image anthony.johnson ♦♦ Axel Kohonen commented ·

Yeah, that's another good reason for using dlls, since FlexScript's file read/write functionality is somewhat limited. I will adjust my comment to say "C++-specific functionality" instead of just "third party functionality".

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.