Navigation:  Language Reference > Functions > External >


Previous pageReturn to chapter overviewNext page


 y = dll(filename, functionname, x);


Given a function (functionname) of a dll (filename), the dll function returns the output values (y) for a given input (x).


Users can write their own source code using a native compiler such as Visual C++ or Borland C++. With these compilers it is possible to create DLLs with user defined functions that have an input- output relation which can be embedded in simulation code.



         string filename = 'example.dll';

         string function = 'myFunction';


         real x[2], y[2];


         x = [ramp(1); ramp(2)];

         y = dll(filename, function, x);



filename and functionname must be string parameters. Note that the size of Y and X (scalars or matrices) must correspond with the size that is expected for the given dll-function.

Search Order

20-sim uses the following search order for the dll-file:

1.The bin directory of 20-sim (usually C:\Program Files\20-sim 5.1\bin).
2.The current directory.
3.A directory that is entered in list of paths in the General Properties dialog (choose Tools - Options - Folders - DLL Search Paths). Use this option to store DLL's in a central location.
4.The Windows system directory.
5.The Windows directory.
6.The directories that are listed in the PATH environment variable.

The simplest place to put the DLL-file is the bin directory, but it is always possible to give a complete path for the DLL filename.


Code generation notice

20-sim allows for code generation of the 20-sim model. In case of a DLL call, 20-sim cannot generate the complete code for a DLL call since it only knows the DLL file name, function name and arguments and not the internal DLL code.

Therefore, in the generated code, the dll(dll_name, function_name, in) will be generated as:


%dll_name%_%function_name%(double *inarr, int inputs, double *outarr, int outputs, int major)

Where %dll_name% and %function_name% are replaced with the actual DLL and function name. You have to add the C-code implementation of this function yourself to the generated code before you can compile it.