Extension.cpp 613 B

123456789101112131415161718192021222324252627282930313233
  1. #include <dlfcn.h>
  2. #include "Extension.h"
  3. bool Extension::load(const char* filename)
  4. {
  5. // load libary
  6. libHandle = dlopen(filename, RTLD_LAZY);
  7. if(libHandle == NULL)
  8. {
  9. ERROR("File \"" << filename << "\": " << dlerror());
  10. return false;
  11. }
  12. // get FooBar
  13. foobarPtr = (int(*)(void*))(dlsym(libHandle, "FooBar"));
  14. if(foobarPtr == NULL)
  15. {
  16. ERROR("File \"" << filename << "\": \"FooBar\" entry symbol not found: " << dlerror());
  17. return false;
  18. }
  19. return true;
  20. }
  21. void Extension::unload()
  22. {
  23. DEBUG_ERR(libHandle==NULL || foobarPtr==NULL);
  24. dlclose(libHandle);
  25. libHandle = NULL;
  26. foobarPtr = NULL;
  27. }