LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-24-2006, 09:54 PM   #1
arunka
Member
 
Registered: Mar 2005
Posts: 60

Rep: Reputation: 15
Call back method for shared library


Hi All,

i wrote an application which loads shared libraries at run time.
my question : is there any way a shared libray can call a method/funtion which is defines in the application?

Can we do this ?if yes how to do it.

Can any one help me?

thanks in adavnce
Arun.
 
Old 02-25-2006, 01:10 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Sure - just use a "callback":

1. Your library function has a parameter that's a pointer to a function.

2. You program that calls the library function defines the actual function
(which is the "callback function.

3. When your program calls the library function, it passes the callback.

4. Your library invokes the callback.

Examples of "callbacks" are numerous:

* signal handlers (in the Linux world)
* WinProc (in "classic Windows" programming)
* GTK+ event handlers
* etc etc

Try "man signal", for example.
 
Old 02-25-2006, 11:43 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
The code of cpufreqd is a nice real-world example about how to load shared libraries as 'plugins' and let them register several call-back functions that get called from the main program.

As it is a complete program, it may look a bit tedious to dive into, but the code is quite clean IMHO, and not too big.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I get every shared library at? Balkman Linux - General 2 08-28-2004 10:56 PM
help shared library jingle_mj Programming 4 08-13-2004 04:13 AM
help shared library jingle_mj Linux - General 1 08-13-2004 03:11 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM
Call Back penguin Linux - Networking 0 01-20-2004 03:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration