-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllproxy.h
More file actions
39 lines (33 loc) · 979 Bytes
/
Copy pathdllproxy.h
File metadata and controls
39 lines (33 loc) · 979 Bytes
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
#pragma once
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <map>
#include <string>
class DLLProxy
{
private:
std::map<std::string, HMODULE> LoadedModules;
public:
HMODULE XLoadLibrary(const char* Source) {
auto mod = LoadedModules.find(std::string(Source));
if (mod != LoadedModules.end()) {
return mod->second;
}
char dirBuffer[MAX_PATH] = { };
GetSystemDirectoryA(dirBuffer, MAX_PATH);
strcat_s(dirBuffer, MAX_PATH, "\\");
strcat_s(dirBuffer, MAX_PATH, Source);
auto lib = LoadLibraryA(dirBuffer);
LoadedModules.emplace(std::string(Source), lib);
return lib;
}
void* XLoadExport(const char* lpProcName, const char* Source) {
auto mod = XLoadLibrary(Source);
auto procAddress = GetProcAddress(mod, lpProcName);
if (!procAddress)
return 0;
return procAddress;
}
};