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

typedef struct tags {
    int i; 
    double d;
} tags_t;
typedef class tagc {
  public:
    int i; 
    double d;
} tagc_t;
typedef union tagu {
    int i; 
    double d;
} tagu_t;

void chuserdefinedname (struct tags s, struct tags *sp, 
                        tagc_t *cp, union tagu u) {
    void *fptr, *handle;

    handle = dlopen("libchcpp.dl", RTLD_LAZY);
    if(handle == NULL) {
      printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
      return;
    }
    fptr = dlsym(handle, "chuserdefinedname_chdl");
    if(fptr == NULL)  {
       printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
       return;
    }
    dlrunfun(fptr, NULL, NULL, s, sp, cp, u);
    if(dlclose(handle)!=0) {
       printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
       return;
    }
    va_end(ap);
    return;
}

int main() {
   struct tags s = {10, 20.0};
   struct tagc c = {10, 20.0};
   struct tagu u = {10, 20.0};

   chuserdefinedname(s, &s, &c, u);
   return 0;
}
