/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include<dlfcn.h>
  ...

return_type functionName(data_type1 arg1, data_type2 arg2)
{
  void *dlhandle, *fptr;
  return_type retval;

  /* load the dynamically loaded library */
  dlhandle = dlopen("libproject.dl", RTLD_LAZY);
  if(dlhandle == NULL) {
    fprintf(_stderr, "Error: %s(): dlopen(): %s\n", 
                      __func__, dlerror());
     return FAIL_VALUE;
  }

  /* get the address by function name */
  fptr = dlsym(dlhandle, "functionName_chdl");
  if(fptr == NULL) {
    printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
    return FAIL_VALUE;
  }

  /* call the chdl function in dynamically loaded library */
  /* arguments arg1 and arg2 are passed to chdl function here */
  /* return value will passed from chdl function */
  dlrunfun(fptr, &retval, functionName, arg1, arg2);

  /* close the dynamically loaded library */
  if(dlclose(handle)!=0) {
    fprintf(_stderr, "Error: %s(): dlclose(): %s\n", 
            __func__, dlerror());
    return FAIL_VALUE;
  }

  return retval;
}
