Runtime modular programming

Started by
6 comments, last by Golthar 22 years, 5 months ago
Hi all, Can anybody advice me if its possible to make a program modular and have the components (modules) be added in runtime The language of preference is C/C++ Thanks for help
"There is a $500 fine for detonating explosives within the confines of a city"
Advertisement
This sounds like an OS kind of question to me. On Win32 use the LoadLibrary/FreeLibrary and GetProcAddress API''s.
Yes, check the man pages on dlopen() or LoadLibrary() depending on your OS.

Both basically return a library handle that you can then use with dlsymb() or GetProcAddress() to get a pointer on a named function in the library.

ex: (windows)

{
double (myfunction*)( char* c );

HINSTANCE hlib = LoadLibrary( "MyLib.dll" );
if ( !hlib ) exit( EXIT_FAILURE );

myfunction = GetProcAddress( hlib, "MyFunctinInMyLib" );
if ( !myfunction ) exit( EXIT_FAILURE );

double x = myfunction( "Hail Eris! All Hail Discordia!" );
}

Now YOU and YOU only are responsible for having the right type of function pointer (type checking... what''s that?) and ensuring the existence of the name (beware of C++ name mangling, extern "C" is your friend)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanks for the help :-)

You said, check the manpages, does anybody have an aproach for Linux too?
Thanks for sharing the knowledge I apreciate it :-)

Kindest regards,

Barry
"There is a $500 fine for detonating explosives within the confines of a city"
Sure *creaking sound* as I open my notebook of things coders-should-be-required-to-know.

Everything you want to know is in "Program Library Howto" by David A. Wheeler at http://www.linuxdoc.org/HOWTO/Program-Library-HOWTO/
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanks!

You have been of great help to me
And yes, these are things programers should know, but not always have to deal with.
This is my first time dealing with it
Thanks for all your help, I apreciate it

Kindest regards,

Barry
"There is a $500 fine for detonating explosives within the confines of a city"
That''s why I put them in a notebook (a binder actually...) when I encountered them : ANSI codes, scancodes, the man page for make, ld, the standard filesystem, gcc-specific C extensions ...

If there is a single advice I can give you (from programmer to programmer) is to keep one too.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Good idea,

Will do
Thanks again

Kindest regards,

Barry
"There is a $500 fine for detonating explosives within the confines of a city"

This topic is closed to new replies.

Advertisement