]> git.tdb.fi Git - libs/core.git/blob - source/core/windows/module.cpp
Add a class for loading and accessing modules at runtime
[libs/core.git] / source / core / windows / module.cpp
1 #include "module.h"
2 #include "module_private.h"
3 #include "systemerror.h"
4
5 using namespace std;
6
7 namespace Msp {
8
9 Module::Module(const string &name)
10 {
11         ModuleHandle handle = LoadLibrary(name.c_str());
12         if(!handle)
13                 throw system_error("LoadLibrary");
14
15         priv = new Private;
16         priv->handle = handle;
17 }
18
19 Module::~Module()
20 {
21         FreeLibrary(priv->handle);
22         delete priv;
23 }
24
25 void *Module::get_symbol(const string &name) const
26 {
27         FARPROC result = GetProcAddress(priv->handle, name.c_str());
28         if(!result)
29                 throw system_error("GetProcAddress");
30
31         return reinterpret_cast<void *>(result);
32 }
33
34 } // namespace Msp