Getting startedTop, Main, Index

submited by
Style Pass
2021-06-05 22:00:04

This package implements a foreign function interface (FFI) for Tcl based on the cross-platform C library, dyncall from Daniel Adler and Tassilo Philipp.

A FFI provides the ability for Tcl to invoke, with some limitations, arbitrary functions from any dynamically linked shared library without having to write C code.

Source distributions and binaries for some platforms are available from https://sourceforge.net/projects/magicsplat/files/cffi.

The following examples illustrate basic usage of the package. Most examples use Windows as they have standard system libraries in known locations. The usage is identical on other platforms.

This creates a shared library object that can then be used for defining functions implemented within the library. It is recommended to always pass a full path to the shared library though that is not strictly required on Windows.

To call this function from Tcl we first have to define a prototype for it. Prototypes can be defined with either the function or stdcall methods on the shared library object that implements the function. The two commands are identical on all platforms except 32-bit Windows where function is used to call functions that use the C calling convention while stdcall is used to call functions using the stdcall calling convention. On all other platforms, including 64-bit Windows, the two are identical. Since we are demonstrating using Windows, the stdcall command is used in some of the examples.

Leave a Comment