Skip to content

Commit

Permalink
New Module class for dynamic library linking
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Nov 11, 2017
1 parent f802a73 commit ea56b09
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
48 changes: 45 additions & 3 deletions src/xrCore/ModuleLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,53 @@

#include "ModuleLookup.hpp"

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

namespace XRay
{
Module::Module() : handle(nullptr) {}

Module::Module(pcstr moduleName, bool log /*= true*/)
{
open(moduleName, log);
}

Module::~Module()
{
close();
}

void* Module::open(pcstr moduleName, bool log /*= true*/)
{
if (exist())
close();

if (log)
Log("Loading DLL:", moduleName);

handle = ::LoadLibrary(moduleName);
return handle;
}

void Module::close()
{
FreeLibrary(static_cast<HMODULE>(handle));
handle = nullptr;
}

bool Module::exist() const
{
return handle != nullptr;
}

void* Module::operator()() const
{
return handle;
}

void* Module::getProcAddress(pcstr procName) const
{
return ::GetProcAddress(static_cast<HMODULE>(handle), procName);
}

HMODULE LoadLibrary(const char* libraryFileName, bool log)
{
if (log)
Expand Down
19 changes: 19 additions & 0 deletions src/xrCore/ModuleLookup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

namespace XRay
{
class XRCORE_API Module
{
void* handle;

public:
Module();
Module(pcstr moduleName, bool log = true);
~Module();

void* open(pcstr moduleName, bool log = true);;
void close();

bool exist() const;

void* operator()() const;

void* getProcAddress(pcstr procName) const;
};

XRCORE_API HMODULE LoadLibrary(const char* libraryFileName, bool log = true);
XRCORE_API void UnloadLibrary(HMODULE libraryHandle);
XRCORE_API void* GetProcAddress(HMODULE libraryHandle, const char* procName);
Expand Down

0 comments on commit ea56b09

Please sign in to comment.