2
Example program for the claw::dynamic_library class.
6
#include <claw/dynamic_library.hpp>
9
# define DLLEXPORT __declspec(dllexport)
14
typedef void (*function_type)( const std::string& s );
17
DLLEXPORT void in_program( const std::string& s )
19
std::cout << "in_program : " << s << std::endl;
22
int main( int argc, char** argv )
26
std::cout << argv[0] << " method_name...\n";
27
std::cout << "\tThe first method_name is searched in the current "
29
std::cout << "\tThe next arguments are searched in the ./libfunc.so "
30
<< "shared library." << std::endl;
34
/* Load the library. */
36
claw::dynamic_library dl( "./libfunc.dll" );
38
claw::dynamic_library dl( "./libfunc.so" );
41
/* Load the current program. */
42
claw::dynamic_library current_prog( argv[0], true );
46
/* Search in the current program. */
47
if ( current_prog.have_symbol( argv[1] ) )
49
f = current_prog.get_symbol<function_type>( argv[1] );
50
f( "The string passed to a method in the current program" );
53
std::cout << "Symbol '" << argv[1]
54
<< "' not found in the current program." << std::endl;
56
/* We try to find the next symbols passed as arguments */
57
for (int i=2; i<argc; ++i)
58
if ( dl.have_symbol( argv[i] ) )
60
f = dl.get_symbol<function_type>( argv[i] );
62
f( "The string passed to the method" );
65
std::cout << "Symbol '" << argv[i] << "' not found." << std::endl;