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

void setFunction1(int arg1, void (*funptr)()) {
  void *dlhandle, *fptr;

  dlhandle = dlopen("libsetfuncptr.dl", RTLD_LAZY);
  if(dlhandle == NULL) {
    printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
    return;
  }
  fptr = dlsym(dlhandle, "setFunction1_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 to C space */
  dlrunfun(fptr, NULL, setFunction1, arg1, funptr);

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