summaryrefslogtreecommitdiff
path: root/shared/dllLoader.cpp
blob: e37ded54c72111575eb961580b3f31e9f46b40fd (plain)
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
41
42
43
44
#include "dllLoader.h"
#include <wx/msw/wrapwin.h> //includes "windows.h"

namespace
{
class KernelDllHandler //dynamically load "kernel32.dll"
{
public:
    static const KernelDllHandler& getInstance()
    {
        static KernelDllHandler instance;
        return instance;
    }

    HINSTANCE getHandle() const
    {
        return hKernel;
    }

private:
    KernelDllHandler() :
        hKernel(NULL)
    {
        //get a handle to the DLL module containing required functionality
        hKernel = ::LoadLibrary(L"kernel32.dll");
    }

    ~KernelDllHandler()
    {
        if (hKernel) ::FreeLibrary(hKernel);
    }

    HINSTANCE hKernel;
};
}


void* Utility::loadSymbolKernel(const std::string& functionName)
{
    if (KernelDllHandler::getInstance().getHandle() != NULL)
        return reinterpret_cast<void*>(::GetProcAddress(KernelDllHandler::getInstance().getHandle(), functionName.c_str()));
    else
        return NULL;
}
bgstack15