2
0
mirror of https://github.com/boostorg/dll.git synced 2026-02-18 01:52:23 +00:00

Polishing examples and docs

This commit is contained in:
Antony Polukhin
2014-09-29 20:41:35 +04:00
parent 90c3903acf
commit 1bdaf08e01
3 changed files with 12 additions and 13 deletions

View File

@@ -4,8 +4,6 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "../shared_lib_path.hpp"
//[callplugcpp_tutorial3
#include <boost/dll/import_function.hpp> // for import_function_alias
#include <boost/make_shared.hpp>
@@ -20,7 +18,7 @@ std::size_t search_for_symbols(const std::vector<boost::filesystem::path>& plugi
for (std::size_t i = 0; i < plugins.size(); ++i) {
std::cout << "Loading plugin: " << plugins[i] << '\n';
lib->load(plugins[i]);
lib->load(plugins[i], dll::load_mode::append_decorations);
if (!lib->search_symbol("create_plugin")) {
// no such symbol
continue;
@@ -41,11 +39,12 @@ std::size_t search_for_symbols(const std::vector<boost::filesystem::path>& plugi
//]
int main(int argc, char* argv[]) {
// argv[1] contains path to our plugin library
BOOST_ASSERT(argc >= 2);
/*<-*/ BOOST_ASSERT(argc >= 2); /*->*/
// argv[1] contains path to our plugin library
std::vector<boost::filesystem::path> plugins;
plugins.push_back(shared_lib_path(argv[1], L"my_plugin_aggregator"));
plugins.push_back(shared_lib_path(argv[1], L"my_plugin_sum"));
boost::filesystem::path base_dir = argv[1];
plugins.push_back(base_dir / "my_plugin_aggregator");
plugins.push_back(base_dir / "my_plugin_sum");
const std::size_t res = search_for_symbols(plugins);
BOOST_ASSERT(res == 1);

View File

@@ -50,10 +50,11 @@ inline boost::shared_ptr<my_refcounting_api> get_plugin(
boost::filesystem::path path, boost::string_ref func_name)
{
typedef my_refcounting_api*(func_t)();
boost::function<func_t> f
= boost::dll::import_function_alias<func_t>(
path, func_name
);
boost::function<func_t> f = boost::dll::import_function_alias<func_t>(
path,
func_name,
boost::dll::load_mode::append_decorations // will be ignored for executable
);
// `f` goes out of scope here and will be destroyed.
// Returned variable holds a reference to

View File

@@ -5,7 +5,6 @@
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//[callplugcpp_tutorial8
#include "../shared_lib_path.hpp"
#include <iostream>
#include "refcounting_api.hpp"
@@ -16,7 +15,7 @@ int main(int argc, char* argv[]) {
BOOST_ASSERT(argc >= 2);
//->
boost::shared_ptr<my_refcounting_api> plugin = get_plugin(
shared_lib_path(argv[1], L"refcounting_plugin"),
boost::filesystem::path(argv[1]) / "refcounting_plugin",
"create_refc_plugin"
);