Solved

Developing plugins: shmop vs dlopen

Posted on 1997-11-12
2
283 Views
Last Modified: 2013-12-26
I am trying to implement the concept of plugins for an application that we are writing.  I am thinking about using shared arenas to communicate between the main application and the plugins.  I'm new at this, and I'm not sure if this is the best way to go.  I have heard about dlopen, but I don't have alot of documentation on how to use it.

Which would be better to use, shmop or dlopen/dlsym?  Also, can anyone lead me to good resource on dlopen?

By the way, the application and plugins will be in C, and we are running IRIX 6.2.  And, platform portability is an issue; we want to be able to port to Windows NT.

Thanks,
Ash
0
Comment
Question by:chopin111297
2 Comments
 
LVL 4

Accepted Solution

by:
jos010697 earned 100 total points
ID: 1295584
You can definitely use dlopen and friends. Compile and link
your plugin as a shared object (a dynamic link library). Check
your manuals for the appropriate linker flags. Suppose the
name of this shared object is 'foo.so' and it contains a
functions 'bar'. This is the way to run this function from
your main application:

typedef int (*fp_t)(int); /* a function poiner */

void* so_object;
fp_t  func;

if (so_object= dlopen("foo.so", 1)) { /* open shared object */
   if (func= dlsym(so_object, "bar") {  /* get address of bar */
      printf("bar42 returned %d\n", func(42));
   else
      printf("couldn't find bar: %s ...\n", dlerror());

   dlclose(so_object); /* close shared object */
}
else
   printf("couldn't open foo.so: %s\n", dlerror());

That's basically all there is to it:

1: dlopen() the shared object
2: retrieve the address of a function (or data) using dlsym()
3: close everthing afterwards using dlclose()
4: if an error occured, dlerrror() returns an error string

kind regards,

Jos aka jos@and.nl

0
 

Author Comment

by:chopin111297
ID: 1295585
Does anyone know of a good resource on the use of dlopen?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 111
Prevent this page from creating additional dialogs. 3 403
if loop in java 3 128
changeXy challenge 13 67
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now