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

void setFunction4(data_type1 arg1, return_type(* funptr)(data_type2)) {
  void *dlhandle, *fptr;

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

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

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