main.pas 947 B

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