tutorial6.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
  2. // Copyright 2015-2019 Antony Polukhin.
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include "../b2_workarounds.hpp"
  8. //[callplugcpp_tutorial6
  9. #include <boost/dll/import.hpp>
  10. #include <boost/function.hpp>
  11. #include <iostream>
  12. typedef boost::function<void()> callback_t;
  13. void print_unloaded() {
  14. std::cout << "unloaded" << std::endl;
  15. }
  16. int main(int argc, char* argv[]) {
  17. // argv[1] contains full path to our plugin library
  18. boost::dll::fs::path shared_library_path = /*<-*/ b2_workarounds::first_lib_from_argv(argc, argv); /*->*/ //=argv[1];
  19. // loading library and getting a function from it
  20. boost::function<void(const callback_t&)> on_unload
  21. = boost::dll::import_alias<void(const callback_t&)>(
  22. shared_library_path, "on_unload"
  23. );
  24. on_unload(&print_unloaded); // adding a callback
  25. std::cout << "Before library unload." << std::endl;
  26. // Releasing last reference to the library, so that it gets unloaded
  27. on_unload.clear();
  28. std::cout << "After library unload." << std::endl;
  29. }
  30. //]