Add an example for GModule usage. (#144127, Tommi Komulainen)
authorMatthias Clasen <maclas@gmx.de>
Fri, 11 Jun 2004 01:31:02 +0000 (01:31 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 11 Jun 2004 01:31:02 +0000 (01:31 +0000)
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)

docs/reference/ChangeLog
docs/reference/glib/tmpl/modules.sgml

index b45bc5768032f3a68b31d41a5f6e9472d2deb0c5..f3ef0a73d5a408b17a03364c8454ede96a738a12 100644 (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()
index 58d6de334fa46e8f765d069a4bbe71494e33de4f..db2e00070264314a5ca94c92aac35d6a68273ac7 100644 (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>