1 program plugin_test;
2 
3 uses
4   glib2;
5 
6 const
7   PLUGIN_NAME = 'plugin';
8   SYMBOL_NAME = 'get_plugin_info';
9 
10 var
11   module   : PGModule;
12   func     : function : pgchar;
13   id       : pgchar;
14   filename : pgchar;
15 
16 begin
17   if not g_module_supported then
18   begin
19     g_error ('No GModule support on this platform.'#13#10);
20     exit;
21   end;
22   filename := g_module_build_path ('.',PLUGIN_NAME);
23   g_print ('Trying to locate module; using %s as filename'#13#10,
24             [filename]);
25 
26   module := g_module_open (filename, G_MODULE_BIND_MASK);
27 
28   if module = NULL then
29   begin
30     g_error ('Couldn''t find Module %s!'#13#10, [PLUGIN_NAME]);
31     exit;
32   end;
33 
34   if not g_module_symbol (module, SYMBOL_NAME, @func) then
35   begin
36     g_error ('No symbol %s in %s found!'#13#10, [SYMBOL_NAME, PLUGIN_NAME]);
37     g_module_close (module);
38     exit;
39   end;
40 
41   id := func();
42 
43   g_print ('Plugin defined itself as "%s"'#13#10, [id]);
44 
45   g_module_close (module);
46 end.
47