1 // Copyright 2016 Klemens Morgenstern
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 // For more information, see http://www.boost.org
8 
9 #include "../b2_workarounds.hpp" // contains dll_test::replace_with_full_path
10 
11 //[import_class_setup
12 
13 #include <boost/dll/smart_library.hpp>
14 #include <boost/dll/import_mangled.hpp>
15 #include <boost/dll/import_class.hpp>
16 
17 
18 
main(int argc,char * argv[])19 int main(int argc, char* argv[]) {
20     /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/
21     boost::dll::fs::path lib_path(argv[1]);      // argv[1] contains path to directory with our plugin library
22     smart_library lib(lib_path);// smart library instance
23 //]
24 //[import_class_size
25     auto size_f = import_mangled<std::size_t()>("space::my_plugin::size"); //get the size function
26 
27     auto size = (*size_f)();             // get the size of the class
28 //]
29 //[import_class_value
30     auto value = import_mangled<int>(lib, "space::my_plugin::value");
31 //]
32 //[import_class_ctor
33     auto cl = import_class<class alias, const std::string&>(lib, "space::my_plugin::some_class", size, "MyName");
34 //]
35 //[import_class_name
36     auto name = import_mangled<const alias, std::string()>(lib, "name");
37     std::cout << "Name: " << (cl->*name)() << std::endl;
38 //]
39 //[import_class_calc
40     auto calc = import_mangled<alias, float(float, float), int(int, int)>(lib, "calculate");
41     std::cout << "Calc(float): " (cl->*calc)(5.f, 2.f) << std::endl;
42     std::cout << "Calc(int):   " (cl->*calc)(5, 2)     << std::endl;
43 //]
44 //[import_class_typeinfo
45     std::type_info &ti = cl.get_type_info();
46 //]
47 }
48