Re: [gtkmm] g_module
- From: ERDI Gergo <cactus cactus rulez org>
- To: Murray Cumming <murrayc usa net>
- Cc: Sarah Leitner <leitners spawar navy mil>, gtkmm-list <gtkmm-list gnome org>
- Subject: Re: [gtkmm] g_module
- Date: Fri, 2 Aug 2002 11:06:12 +0200 (CEST)
On 2 Aug 2002, Murray Cumming wrote:
> However, if you need something to find C++ symbols at runtime rather
> than C symbols then life will probably be more difficult due to C++ name
> mangling. If that's what you need then I suggest that you look at
> libglademm 0.x (The GNOME 1.4 version in sourceforge). The original
> author seemed to have some solution for this. I haven't put that stuff
> into libglademm2 yet because I have not had time to understand it.
I have a pretty simple solution for this:
class PluggableBase
{
public:
virtual ~PluggableBase () {};
virtual void foo () = 0;
virtual void bar () = 0;
typedef PluggableBase* (*creator_t) (const T1& param1, int param2);
};
Then in a plugin .cc:
class PluggableImplA: public PluggableBase
{
//...
};
extern "C" PluggableBase* create_pluggable (const T1& param1, int param2)
{
return new PluggableImplA (param1, param2);
}
The important part is that create_pluggable should be linked as a C
function to avoid name mangling.
Usage with the C API of g_module is very simple (using the 1.2 API here):
GModule *plugin_handle = g_module_open ("foo.so", G_MODULE_BIND_LAZY);
chkerror(g_module_error());
gpointer creator_func_p;
if (!g_module_symbol (plugin_handle, "create_pluggable", &creator_func_p))
chkerror(g_module_error());
PluggableBase::creator_t create_func =
static_cast<PluggableBase::creator_t> creator_func_p;
PluggableBase *plugin_obj = creator_func (P1, 10);
return plugin_obj;
--
.--= ULLA! =---------------------. `We are not here to give users what
\ http://cactus.rulez.org \ they want' -- RMS, at GUADEC 2001
`---= cactus cactus rulez org =---'
Ha nem jó eredmény jön ki, szorozd be az oldalszámmal.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]