Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Dynamic library code out of util in to dynamic library file
- Loading branch information
Showing
9 changed files
with
73 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "DynamicLibrary.h" | ||
#ifdef _WIN32 | ||
#include <windows.h> | ||
#else | ||
#include <unistd.h> | ||
#include <dlfcn.h> | ||
#include <errno.h> | ||
#endif | ||
|
||
DynLibHandle DynamicLibraryOpen(const char *pccLibraryPath, bool ShowErrors) | ||
{ | ||
if (pccLibraryPath == nullptr) | ||
{ | ||
return nullptr; | ||
} | ||
#ifdef _WIN32 | ||
UINT LastErrorMode = SetErrorMode(ShowErrors ? 0 : SEM_FAILCRITICALERRORS); | ||
DynLibHandle Lib = (DynLibHandle)LoadLibraryA(pccLibraryPath); | ||
SetErrorMode(LastErrorMode); | ||
#else | ||
pjutil::DynLibHandle Lib = (pjutil::DynLibHandle)dlopen(pccLibraryPath, RTLD_NOW); | ||
#endif | ||
return Lib; | ||
} | ||
|
||
void DynamicLibraryClose(DynLibHandle Lib) | ||
{ | ||
if (Lib != nullptr) | ||
{ | ||
#ifdef _WIN32 | ||
FreeLibrary((HMODULE)Lib); | ||
#else | ||
dlclose(Lib); | ||
#endif | ||
} | ||
} | ||
|
||
void * DynamicLibraryGetProc(DynLibHandle Lib, const char * ProcedureName) | ||
{ | ||
if (ProcedureName == nullptr) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
#ifdef _WIN32 | ||
return GetProcAddress((HMODULE)Lib, ProcedureName); | ||
#else | ||
return dlsym(Lib, ProcedureName); | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
typedef void * DynLibHandle; | ||
|
||
DynLibHandle DynamicLibraryOpen(const char * LibraryPath, bool ShowErrors = true); | ||
void DynamicLibraryClose(DynLibHandle LibHandle); | ||
void * DynamicLibraryGetProc(DynLibHandle LibHandle, const char * ProcedureName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters