P
Pelle Beckman
Hi,
I read a tutorial on function pointers in a swedish computer magazine.
The author used functions named dlopen() and dlsym()
(found in "dlfcn.h" under linux) that gave him the ability to get
function pointers from strings, ie :
typedef int (*fp) (int, int);
(...)
void *handle = dlopen (argv[1], RTLD_LAZY);
fp m = (fp) dlsym (handle, "the_magic_string_method");
(...)
cout << "Result from the_magic_etc... " << (*m)(x, y) << endl;
(...)
dlclose (handle);
The questions:
* What is this?
* How does it work
And perhaps more importantly.
* can it be used with gcc (mingw32) under win32 (winxp)?
Links, tutorials, anyone?
Thanks.
-- Pelle
I read a tutorial on function pointers in a swedish computer magazine.
The author used functions named dlopen() and dlsym()
(found in "dlfcn.h" under linux) that gave him the ability to get
function pointers from strings, ie :
typedef int (*fp) (int, int);
(...)
void *handle = dlopen (argv[1], RTLD_LAZY);
fp m = (fp) dlsym (handle, "the_magic_string_method");
(...)
cout << "Result from the_magic_etc... " << (*m)(x, y) << endl;
(...)
dlclose (handle);
The questions:
* What is this?
* How does it work
And perhaps more importantly.
* can it be used with gcc (mingw32) under win32 (winxp)?
Links, tutorials, anyone?
Thanks.
-- Pelle