/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include<dlfcn.h>
  ...
void functionName(data_type1 param, ...)
{
  void *dlhandle, *fptr;
  int vacount, i;
  ChVaList_t ap;
  data_typy2 arg;

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

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

  va_start(ap, param);
  vacount = va_count(ap);

  if(vacount == 0)
    dlrunfun(fptr, NULL, functionName, param);
  else
    for(i = 1; i <= vacount; i++) {
      arg = va_arg(ap, data_type2); 
      dlrunfun(fptr, NULL, functionName, param, arg);
    }

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