Dynamic Linking to external code

Dynamic Linking to external code

include adv/dll.e

Functions/Procedures
Subtopics

Dynamic Linking to external code

[func]
define_c_func
( object lib, object routine_name, sequence arg_types, atom return_type )

Category: Dynamic Linking to external code

Define the paramaters of a C function or machine-code routine that returns a value.

Parameters

  1. lib : an object, either an entry point returned by open_dll, or "" to denote a routine in memory.
  2. routine_name : an object, either the name of a function in the shared library or the memory address of the machine-code routine.
  3. arg_types : a sequence, a list of C Type constants for each argument.
  4. return_type : an atom, the type constant or the return value.

Returns

A small integer, the routine id of the function.

Comments

The length of routine_name should not exceed 1,024 characters.

Use the returned value as the first parameter to c_func or c_proc. A returned value of -1 indicates that the function could not be found.

On Windows, you can add a '+' character as a prefix to the function name. This indicates to Euphoria that the function uses the CDECL calling convention. By default, Euphoria assumes that C routines accept STDCALL convention on Windows. See open_dll on how to force this for all functions in a given library.

If you are not interested in using the value returned by the C function, you should instead define it with define_c_proc and call it with c_proc.

By default, define_c_func will crash your application if it cannot find the function. See Errors and debugging for more details.

See also: define_c_proc, c_func, c_proc


Dynamic Linking to external code

[func]
define_c_proc
( object lib, object routine_name, sequence arg_types )

Category: Dynamic Linking to external code

Define the paramaters of a C function or machine-code routine does not return a value.


Dynamic Linking to external code

[func]
define_c_var
( atom lib, sequence variable_name )

Category: Dynamic Linking to external code

Gets the memory address of a symbol in a shared library.

Parameters

  1. lib : an atom, the address of the shared library from open_dll
  2. variable_name : a sequence, the name of the exported C variable in the library

Returns

An atom, the memory address of variable_name.

Comments

Once you have the address of a C variable, and you know its type, you can use peek and poke to read or write the value of the variable.

By default, define_c_var will crash your application if it cannot find the variable. See Errors and debugging for more details.

See also: peek, peeks, peek2s, peek2u, peek4s, peek4u, peek_string, peek_wstring, poke, poke2, poke4, poke_string, poke_wstring


Dynamic Linking to external code

[const]
NULL

Category: Dynamic Linking to external code

A null pointer.


Dynamic Linking to external code

[func]
open_dll
( sequence file_name, types:boolean use_cdecl = 0 )

Category: Dynamic Linking to external code

Open a Windows dynamic link library (.dll) file, or a Unix shared library (.so) file.

Parameters

  1. file_name : a sequence, the name of the shared library to open or a sequence of filenames to try and open.
  2. use_cdecl : an integer, if non-zero, then force all routines in this library to be declared as CDECL instead of STDCALL

Returns

An atom, actually a 32-bit address. 0 is returned if the library cannot be loaded.

Comments

The use_cdecl flag only applies to Windows. Setting it on other platforms has no effect.

By default, open_dll will crash your application if it cannot load a library. See Errors and debugging for more details.

See also: define_c_var, define_c_func, define_c_proc, c_func, c_proc