2002-10-12 09:52:15 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ltdl.h>
|
|
|
|
#define MAIN_DLL_EXPORT
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
const char *version_string = "uselib-test6-1.0";
|
|
|
|
|
|
|
|
int register_module (const char *name)
|
|
|
|
{
|
|
|
|
printf ("register_module was called by module '%s'\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module (const char *fmt, const char *name)
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
sprintf (buf, fmt, name);
|
2002-10-12 15:50:28 +04:00
|
|
|
if (lt_dlinit () != 0) {
|
|
|
|
printf ("lt_dlinit error: %s\n", lt_dlerror ());
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-12 09:52:15 +04:00
|
|
|
lt_dlhandle handle = lt_dlopen (buf);
|
2002-10-12 15:50:28 +04:00
|
|
|
printf ("handle is %p\n", handle);
|
2002-10-12 09:52:15 +04:00
|
|
|
if (!handle) {
|
|
|
|
printf ("lt_dlopen error: %s\n", lt_dlerror ());
|
2002-10-12 15:50:28 +04:00
|
|
|
return -1;
|
2002-10-12 09:52:15 +04:00
|
|
|
}
|
2002-10-12 15:50:28 +04:00
|
|
|
modload_func func = (modload_func) lt_dlsym (handle, "module_init");
|
2002-10-12 09:52:15 +04:00
|
|
|
printf ("module_init function is at %p\n", func);
|
|
|
|
if (func != NULL) {
|
|
|
|
printf ("Calling module_init\n");
|
|
|
|
(*func)();
|
|
|
|
} else {
|
2002-10-12 15:50:28 +04:00
|
|
|
printf ("lt_dlsym error: %s\n", lt_dlerror ());
|
|
|
|
return -1;
|
2002-10-12 09:52:15 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
printf ("start\n");
|
|
|
|
printf ("loading module1\n");
|
|
|
|
// try to load module1
|
|
|
|
if (load_module ("%s", argv[1]) < 0) {
|
|
|
|
printf ("load %s failed\n", argv[1]);
|
|
|
|
}
|
|
|
|
if (load_module ("%s.la", "module1") < 0) {
|
|
|
|
printf ("load module1 failed\n");
|
|
|
|
}
|
|
|
|
if (load_module ("%s.la", "module2") < 0) {
|
|
|
|
printf ("load module2 failed\n");
|
|
|
|
}
|
|
|
|
printf ("stop\n");
|
|
|
|
return 0;
|
|
|
|
}
|