Jye S avatar image
Jye S asked Phil BoBo edited

Module Development for C++ User Commands

I've recently been going over and over the Module SDK documentation as our team is hoping to make use of this functionality, particularly for developing user commands in C++ and within an IDE. I went through the documentation and the included examples, I was able to get the Snow Processor example to work just fine and I tried to use this knowledge to work out how we could add user commands to FlexSim through a DLL.

I've worked over this for a few days and I've yet to quite work it out so I was hoping to get some guidance on where I'm going wrong. I've started with the basic visual studio project template from the FlexSim site and have followed the documentation for setting up and building the DLL. I'm able to get the project to build just fine and I've gone into the FlexSim tree to set up a new user command through a test module as shown in the screenshot below. I'm able to get FlexSim to recognise the function but the actual linking to the DLL seems to throw errors as you can see in the system console.

fs.pngI've included a link to the module here (couldn't upload it due to size limits) and hopefully between that and seeing how I've set up the tree you can let me know where I'm going wrong. The documentation doesn't specify where exactly to place the function within the VS project, so I played around with placing the function in the module class, as well as its own C++ class, then using the createsdtderivative() function to try create that individual class.

Thanks for you help.

FlexSim 21.1.4
module sdkuser commandsdkuser commandsmodule development
fs.png (44.8 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

Phil BoBo avatar image
Phil BoBo answered Phil BoBo edited

1. Your output is a file without an extension. Make sure your project target is generating a dll file:


2. Your flexsimcontent files are not from the target FlexSim version, so the dll has unsuccessful bindings that prevent it from loading:


Copy the correct flexsimcontent headers from the target version of FlexSim that you are compiling against:


3. Your function needs to have the correct signature in order to be accessed as a user command. It must return a double and have a particular set of parameters. The FLEXSIMINTERFACE macro defines these parameters:


4. The text of your node has to be correctly formatted with the path to the dll and function. You have 2 semicolon characters where you should only have 1.


1627479981885.png (133.1 KiB)
1627480044172.png (29.3 KiB)
1627480072152.png (234.8 KiB)
1627480194305.png (91.5 KiB)
1627480297125.png (42.2 KiB)
· 8
5 |100000

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

Jye S avatar image Jye S commented ·
Hi @Phil BoBo, I appreciate your quick reply.

Unfortunately, I followed your steps of my mistakes without any luck I'm still getting the same error message mentioned in my original question.

I've made sure to:

  • Build with the correct extension. When I originally built the template_solution it output CustomUserCommands_x86.dll, so I went into the project properties and removed the part adding the x86, this action must have remove the .dll extension, it now simply exports to CustomUserCommands.dll.
  • I've added the headers and FlexSim.lib file into the module > flexsimcontent location (before building the dll).
  • Changed the return type to double, the parameter to FLEXSIMINTERFACE and removed the declaration in the module header file.
  • I removed the extra colon in the DLL linking node.

    I've also reuploaded the module to Google Drive, linked here.

    Really appreciate your help Phil.
1 Like 1 ·
Phil BoBo avatar image Phil BoBo ♦♦ Jye S commented ·

FlexSim is a 64-bit application. You need to change your platform from x86 to x64 so that your dll is built as a 64-bit dll:


Also, make sure your project properties are correct for the specified configuration and platform:


A 64-bit application cannot load a 32-bit x86 dll.

2 Likes 2 ·
1627570159079.png (69.9 KiB)
1627570192752.png (42.7 KiB)
Jye S avatar image Jye S Phil BoBo ♦♦ commented ·

Thanks for your help mate @Phil BoBo , I was able to get it working at last.

As a side note, how do you go about returning strings?

I've tried using the same working function, to change the return type to string and updating the return type within the FlexSim tree, however it wouldn't work. I remember reading in the old DLL Maker that strings weren't supported due to how data is separated, so I tried returning a character array and leaving the return type in the FlexSim tree as string, as well as just trying val for a return type.

I'm not getting errors but the function returns 0.00, or if I save the result to a string variable, then return that variable, it returns "String: 9.22658083014804e-312".

Sorry to keep asking small questions, is there any better documentation on these small caveats? The current documentation seems a bit lacking.

1 Like 1 ·
Show more comments