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

void setFunction2(data_type1 arg1, retrun_type (*funptr)()) {
  void *dlhandle, *fptr;

  dlhandle = dlopen("libproject.dl", RTLD_LAZY);
  if(dlhandle == NULL) {
    printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
    return;
  }
  fptr = dlsym(dlhandle, "setFunction2_chdl");
  if(fptr == NULL) {
    printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
    return;
  }

  /* call the chdl function in dynamically loaded library by address, 
     arguments including function pointer are passed C space */
  dlrunfun(fptr, NULL, setFunction2, arg1, funptr);

  if(dlclose(dlhandle)!=0) {
    printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
    return;
  }
}
