-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.cpp
40 lines (31 loc) · 1.39 KB
/
Loader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "Loader.h"
void Loader::getOperatorFromDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const HINSTANCE& load)
{
std::function<double(double, double)> Operation = (double (*) (double, double))GetProcAddress(load, "operation");
std::function<int(void)> Binary = (int (*) (void))GetProcAddress(load, "binary");
std::function<int(void)> Priority = (int (*) (void))GetProcAddress(load, "priority");
std::function<std::string(void)> Name = (std::string(*) (void)) GetProcAddress(load, "name");
std::function<bool(void)> Associativity = (bool (*) (void))GetProcAddress(load, "associativity");
operations[Name()] = std::move(std::make_unique<Operator>(Name(), Priority(), Associativity(), Binary(), Operation));
}
void Loader::loadDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const std::string& folder, const std::string& extension)
{
std::vector<std::filesystem::path> files;
for (const auto& entry : std::filesystem::directory_iterator(folder))
if (entry.path().extension() == extension)
files.push_back(entry.path().c_str());
const wchar_t* widecFileName;
HINSTANCE load;
for (const auto& path : files)
{
widecFileName = path.c_str();
load = LoadLibraryW(widecFileName);
if (load)
{
libraries.push_back(load);
getOperatorFromDll(operations, load);
}
else
std::cerr << "Opening dll file " << path << " failure" << std::endl;
}
}