4 #if !defined(NO_DLFCN) && !defined(_WIN32) && !defined(_WIN64)
11 #if defined(_WIN32) || defined(_WIN64)
12 std::string callsign
= "dynamic link library";
13 std::string callsign_ext
= "dll";
14 #elif !defined(NO_DLFCN)
15 #if defined(__APPLE__)
16 std::string callsign
= "dynamic library";
17 std::string callsign_ext
= "bundle";
19 std::string callsign
= "shared object";
20 std::string callsign_ext
= "so";
23 std::string callsign
= "";
27 loaded_library::loaded_library(const std::string
& filename
) throw(std::bad_alloc
, std::runtime_error
)
29 #if !defined(NO_DLFCN) && !defined(_WIN32) && !defined(_WIN64)
31 getcwd(buffer
, 16383);
32 std::string _filename
= filename
;
33 if(filename
.find_first_of("/") >= filename
.length())
34 _filename
= buffer
+ std::string("/") + filename
;
35 handle
= dlopen(_filename
.c_str(), RTLD_LOCAL
| RTLD_NOW
);
37 throw std::runtime_error(dlerror());
38 #elif defined(_WIN32) || defined(_WIN64)
40 GetCurrentDirectory(16383, buffer
);
41 std::string _filename
= filename
;
42 if(filename
.find_first_of("/\\") >= filename
.length())
43 _filename
= buffer
+ std::string("/") + filename
;
44 handle
= LoadLibraryA(_filename
.c_str());
46 int errcode
= GetLastError();
47 char errorbuffer
[1024];
48 if(FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, errcode
, 0,
49 errorbuffer
, sizeof(errorbuffer
), NULL
))
50 throw std::runtime_error(errorbuffer
);
52 std::ostringstream str
;
53 str
<< "Unknown system error (code " << errcode
<< ")";
54 throw std::runtime_error(str
.str());
58 throw std::runtime_error("Loading libraries is not supported");
62 loaded_library::~loaded_library() throw()
64 #if !defined(NO_DLFCN) && !defined(_WIN32) && !defined(_WIN64)
66 #elif defined(_WIN32) || defined(_WIN64)
71 void* loaded_library::operator[](const std::string
& symbol
) throw(std::bad_alloc
, std::runtime_error
)
73 #if !defined(NO_DLFCN) && !defined(_WIN32) && !defined(_WIN64)
75 void* s
= dlsym(handle
, symbol
.c_str());
80 throw std::runtime_error(e
);
81 return NULL
; //Yes, real NULL symbol.
82 #elif defined(_WIN32) || defined(_WIN64)
83 void* s
= (void*)GetProcAddress(handle
, symbol
.c_str());
86 int errcode
= GetLastError();
87 char errorbuffer
[1024];
88 if(FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, errcode
, 0,
89 errorbuffer
, sizeof(errorbuffer
), NULL
))
90 throw std::runtime_error(errorbuffer
);
92 std::ostringstream str
;
93 str
<< "Unknown system error (code " << errcode
<< ")";
94 throw std::runtime_error(str
.str());
97 throw std::runtime_error("Library loading not supported");
101 const std::string
& loaded_library::call_library() throw()
106 const std::string
& loaded_library::call_library_ext() throw()