# dlcall

C or Fortran Foreign function call.

## Syntax

* \[x1, ... , xN] = dlcall(dlsym\_handle, arg1, ..., argN)

## Input argument

* dlsym\_handle - a dlsym handle.
* arg1, ..., argN - input arguments.

## Output argument

* \[x1, ... , xN] - output values.

## Description

dlcall calls an external C or Fortran function loaded from an shared library.

dlcall validates input argument types before calling based on dlsym handle definition.

## Examples

```matlab
lib = dlopen([modulepath('nelson', 'builtin'), '/libnlsDynamic_link', getdynlibext()]);
V = double([1 2;3 4]);
% C prototype:
% int dynlibTestMultiplyDoubleArrayWithReturn(double *x, int size)
f = dlsym(lib, 'dynlibTestMultiplyDoubleArrayWithReturn', 'int32', {'doublePtr', 'int32'});
[r1, r2] = dlcall(f, V, int32(numel(V)))
delete(f);
delete(lib);
```

Call C getpid function

```matlab
run([modulepath('dynamic_link'), '/examples/call_c.m']);
```

Call fortran DASUM (blas) function

```matlab
run([modulepath('dynamic_link'), '/examples/call_fortran.m']);
```

## See also

[dlsym](dlsym), [C/Nelson equivalent data types](c_datatype).

## History

| Version | Description     |
| ------- | --------------- |
| 1.0.0   | initial version |

## Author

Allan CORNET
