question

Mischa Spelt avatar image
4 Likes"
Mischa Spelt asked anthony.johnson commented

Returning string from C++ user command

I'm importing an old (7.x) DLL to 17.0 and running into some problems with user commands returning a string. We used to write functions like

  1. visible double DLL_GetDateTimeString( FLEXSIMINTERFACE )
  2. {
  3. stringreturn( "Hello world!" );
  4. return 0;
  5. }

but that does not seem to work anymore. The documentation states that as of FlexSim 2016 one can "simply" return a string from the user command, but I tried a couple of options such as

  1. visible std::string DLL_GetDateTimeString( FLEXSIMINTERFACE )
  2. {
  3. return std::string("Hello world!");
  4. }

and

  1. visible char* DLL_GetDateTimeString( FLEXSIMINTERFACE )
  2. {
  3. std::string result = "Hello world!";
  4. return apchar( result );
  5. }

or

  1. visible const char* DLL_GetDateTimeString( FLEXSIMINTERFACE )
  2. {
  3. std::string result = "Hello world!";
  4. return result.c_str();
  5. }

but they break the stack or give me nonsense output, respectively.

Could you provide an example of how to return strings from a DLL function in version 2017?

FlexSim 17.0.0
user commandc++stringdll functions
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

Phil BoBo avatar image
4 Likes"
Phil BoBo answered anthony.johnson commented

Change your function definition to return a Variant:

  1. __declspec(dllexport) Variant DLL_GetDateTimeString(FLEXSIMINTERFACE)
  2. {
  3. return std::string("Hello world!");
  4. }


return-string.jpg (159.4 KiB)
· 2
5 |100000

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