Compiling Vissim to CCode with user written DLL problem

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Submitted by robin_a on Thu, 09/16/2010 - 13:25

I have a large Vissim model with user written DLLs. I'm trying out the CCode add-on to see if I can improve the speed of simulation and eventually deploy the model to other non vissim users. Unfortunately I'm having a problem compiling the model.

The DLL is based on the Tank32 example given in the VSDK folder, and works fine under Vissim. I've followed the instructions in the Ccode help document which suggests updating the VSMDLL32.bat to include the library file, and adding the function declaration to userdll.h in the following form:

__declspec(dllexport) void _stdcall EXPORT READ_INPUT_FILE(double p[],double in [],double out[]);

for my DLL (based on TANK32) I think this should look like:

__declspec(dllexport) void _stdcall FAR PASCAL EXPORT main (double FAR param[],double FAR inSig[],double FAR outSig[])

I've tried variations on this theme removing each and every keyword (especially FAR) from both the definition in the DLL and the header, and I usually get back to the same error when compiling:

errorC2373: 'main' : redefinition; different type modifiers C:\Vissim70\cg\include\userdll.h(2): see declaration of 'main'<br> NMAKE : fatal error U1077: 'cl' : return code '0x2'

Please could you let me know what I'm doing wrong? I have no problem compiling simple Vissim models, And would find the CCode add-on really useful if I could get over this hurdle,

Thanks
Robin Auckland

Tagged:

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2016

    Submitted by pete on Thu, 09/16/2010 - 20:54.

    'main' is a reserved function name for the C language. Hence the 'redefinition' complaint. 'main' is the first function that is called in any C program. You could use practically any other name you might think of instead of 'main' for your function, but I would generally avoid using names that are in the standard C/C++ library as that would preclude you from using that predefined function (i.e. don't use strcpy, strcmp, sprintf, fwrite etc. as your function name either)

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2016

    Submitted by robin_a on Mon, 09/27/2010 - 21:48.

    Thanks for your help with this problem, I’ve changed my function name from ‘main’ and everything compiles fine. I can run this compiled DLL as a ‘userfunction’ block within vissim and simulation time is dramatically reduced as hoped. Unfortunately I now have 2 further problems.

    1) I cannot run the dll as a standalone executable I hoped to achieve this with the ccode addon to make the tool distributable to non vissim users. While the addon compiles to an .exe I get errors about missing files including vissim32.exe and some dlls, after finding all these the simulation starts and then stops responding and produces no output. Like I say I had hoped to distribute the exe to no vissim users, is there something I’m missing? The same compound block compiles and runs as a user function dll.

    2) There seem to be a few issues with some of the blocks, firstly import and export blocks struggle with headers and large numbers of columns. I’ve written a user dll to deal with these problems, but the bigger problem is with the integrator block. In my model I set the initial condition of the integrator using a variable (which is read in at the start of the simulation and remains constant) but compiling the code fixes the initial condition as the most recent value irrespective of a change to the initial condition ‘variable’. This is a major problem for me as I have a vehicle model that integrates to velocity from acceleration, and I need to be able to set the initial velocity outside of the simulation. Is there a work around for this problem?

    Thanks for any help you can provide,

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2016

    Submitted by pete on Tue, 09/28/2010 - 10:20.

    1) To create a standalone executable, do not check the 'Include VisSim Communication Interface' option. If the diagram you generate standalone code for contains compiled DLL's, those DLL's will want to query VisSim to find out integration methods and sim time. To do this the generated code looks for VisSim32.exe. This means you must call your generated application 'vissim32.exe' so that the DLL's will find your application and not VisSim itself. To avoid this, compile from pure VisSim blocks with no embedded DLLs. If you want to embed your simulation into an application that you are coding by hand, use the simObject target.

    2)We are not aware of any problems with headers or column count with import or export. Please send any examples of problems to support@vissol.com

    3) Regarding initial condition for integrator, you can use a reset integrator with the reset condition = $firstPass and reset value = your initial condition.