www.delorie.com/gnu/docs/dld/dld_9.html   search  
 
Buy GNU books!


Dld

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Invoking Dynamically Linked Functions

Dynamically linked functions may still be invoked from modules (e.g., main) that do not contain references to such functions.

Function: unsigned long dld_get_symbol (const char *id)
Returns the entry point of the function named id if found, 0 if not found. Non-zero returned values can be used as pointers to the functions.

Function: unsigned long dld_get_func (const char *func)
Returns the address of the global variable named func if found, 0 if not found.

A typical use of dld_get_func would be:

 
{
    void (*func) ();
    int error_code;

    ...

    /* First, link in the object file "my_object_file.o".  Proceed
       only if the link operation is successful, i.e. it returns 0.
       "my_new_func" is a function defined in "my_object_file.o".
       Set func to point at the entry point of this function and
       then invoke it indirectly through func. */

    if ((error_code = dld_link ("my_object_file.o")) == 0) {
        if ((func = (void (*) ()) get_func ("my_new_func")) != 0)
            (*func) ();
        ...
    } else {

    ...
    }
}


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003