diff -r 43e37759235e -r 51a74ef9ed63 Symbian3/SDK/Source/GUID-01E7AE98-024C-4119-87D0-5BB9D53DA119.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-01E7AE98-024C-4119-87D0-5BB9D53DA119.dita Wed Mar 31 11:11:55 2010 +0100 @@ -0,0 +1,102 @@ + + + + + +Introduction +to <codeph>libgmodule</codeph>libgmodule has APIs that provide a portable method +for dynamically loading 'plug-ins' or, in other words, DLLs. Any program that +wants to dynamically load modules must be linked to libgmodule. +

In order to use the libgmodule APIs, the user must check +whether dynamic loading of DLLs is supported by the platform by using the g_module_supported() API +which returns TRUE if the dynamic loading of modules is supported. P.I.P.S. +provides the implementation of libdl, where dynamic loading +of modules is supported, but to write code which runs across platforms the +user must do a check before using the libgmodule APIs.

+

If the dynamic loading of DLLs is supported, use g_module_open() to +open the module. It takes the name of the module as the first argument and +the flags as the second argument.

+G_MODULE_BIND_LOCAL is the only flag currently supported. +The other flags are not supported. If the user specifies any other flag, the +module is loaded using the flag G_MODULE_BIND_LOCAL and not +by the user-specified flag. +

GModule * g_module_open(const gchar *file_name, GModuleFlags +flags);

+ +

Once the module is opened, the user can find the module symbols (for example,. +function names) using the function

+

g_module_symbol().

+

gboolean g_module_symbol (GModule *module, const gchar *symbol_name, +gpointer *symbol);

+ +

The GModule can be closed by using the g_module_close() API. +This API returns TRUE if it successfully closed the module; else it returns +FALSE.

+

gboolean g_module_close(GModule *module);

+ +

The following example code explains the usage of the libgmodule APIs. +It opens a module libmoduletestplugin_a.dll and uses +its gplugin_a_func1() API which is ordinal number 1. Finally, +the module is closed.

+#include <gmodule.h> +#include <glib.h> +typedef int (*SimpleFunc) (void); + +int main() +{ + GModule *module = NULL; + gpointer func; + SimpleFunc f_a; + int retVal; + + if (!g_module_supported()) + { + g_print ("Dynamic Opening of modules is not supported"); + return 1; + } + + /* G_MODULE_BIND_LAZY is overridden and the module is opened with + * flag G_MODULE_BIND_LOCAL + */ + module = g_module_open("libmoduletestplugin_a.dll",G_MODULE_BIND_LAZY); + + // 1 is the ordinal number for gplugin_a_func1 + if(module && g_module_symbol(module, "1" ,&func)) + { + f_a = (SimpleFunc)func; + retVal = f_a(); + g_print("Function at ordinal number 1 of module libgmodule_a returns %d",retVal); + } + else + { + g_print("Error quering symbol at ordinal number 1"); + return 1; + } + + return 0; +} +

See the Libgmodule APIs section in Differences +between OSS and Symbian GLib for more details about libgmodule limitations +in the Symbian GLib implementation.

+
\ No newline at end of file