Add an example for GModule usage. (#144127, Tommi Komulainen)

Thu Jun 10 21:29:55 2004  Matthias Clasen  <maclas@gmx.de>

	* glib/tmpl/modules.sgml: Add an example for GModule
	usage.  (#144127, Tommi Komulainen)
This commit is contained in:
Matthias Clasen 2004-06-11 01:31:02 +00:00 committed by Matthias Clasen
parent 47d4ea5f83
commit c441dca3db
2 changed files with 47 additions and 0 deletions

View File

@ -1,3 +1,8 @@
Thu Jun 10 21:29:55 2004 Matthias Clasen <maclas@gmx.de>
* glib/tmpl/modules.sgml: Add an example for GModule
usage. (#144127, Tommi Komulainen)
Sun Jun 6 23:20:42 2004 Matthias Clasen <maclas@gmx.de>
* gobject/tmpl/gtype.sgml: Fix the docs for G_DEFINE_TYPE()

View File

@ -41,6 +41,48 @@ program, e.g. through calling <literal>g_quark_from_static_string ("my-module-st
it must ensure that it is never unloaded, by calling g_module_make_resident().
</para>
<para>
<example>
<title>Calling a function defined in a <structname>GModule</structname></title>
<programlisting>
/* the function signature for 'say_hello' */
typedef void (* SayHelloFunc) (const char *message);
gboolean
just_say_hello (const char *filename, GError **error)
{
SayHelloFunc say_hello;
GModule *module;
module = g_module_open (filename, G_MODULE_BIND_LAZY);
if (!module)
{
g_set_error (error, FOO_ERROR, FOO_ERROR_BLAH,
"&percnt;s", g_module_error (<!-- -->));
return FALSE;
}
if (!g_module_symbol (module, "say_hello", (gpointer *)&amp;say_hello))
{
g_set_error (error, SAY_ERROR, SAY_ERROR_OPEN,
"&percnt;s: &percnt;s", filename, g_module_error (<!-- -->));
if (!g_module_close (module))
g_warning ("&percnt;s: &percnt;s", filename, g_module_error (<!-- -->));
return FALSE;
}
/* call our function in the module */
say_hello ("Hello world!");
if (!g_module_close (module))
g_warning ("&percnt;s: &percnt;s", filename, g_module_error (<!-- -->));
return TRUE;
}
</programlisting>
</example>
</para>
<!-- ##### SECTION See_Also ##### -->
<para>