From f2d10c1590503ff960bf55758bf6898d7b06ac80 Mon Sep 17 00:00:00 2001 From: cfcohen Date: Fri, 4 Dec 2015 19:55:00 -0500 Subject: [PATCH] Revert "Remove unnecessary files." This reverts commit 81336cc3e9cef439fc103ec40c8e6110cfdfe225. --- project/vc9/nvcore/nvcore.vcproj | 8 ++--- src/nvcore/CMakeLists.txt | 1 + src/nvcore/Library.cpp | 45 ++++++++++++++++++++++++++++ src/nvcore/Library.h | 51 ++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/nvcore/Library.cpp create mode 100644 src/nvcore/Library.h diff --git a/project/vc9/nvcore/nvcore.vcproj b/project/vc9/nvcore/nvcore.vcproj index 719e96f..871e896 100644 --- a/project/vc9/nvcore/nvcore.vcproj +++ b/project/vc9/nvcore/nvcore.vcproj @@ -290,10 +290,6 @@ RelativePath="..\..\..\src\nvcore\Array.h" > - - @@ -315,11 +311,11 @@ > +#elif NV_OS_XBOX +#include +#else +#include +#endif + + + +void * nvLoadLibrary(const char * name) +{ +#if NV_OS_WIN32 + return (void *)LoadLibraryExA( name, NULL, 0 ); +#elif NV_OS_XBOX + return (void *)LoadLibraryA( name ); +#else + return dlopen(name, RTLD_LAZY); +#endif +} + +void nvUnloadLibrary(void * handle) +{ + nvDebugCheck(handle != NULL); +#if NV_OS_WIN32 || NV_OS_XBOX + FreeLibrary((HMODULE)handle); +#else + dlclose(handle); +#endif +} + +void * nvBindSymbol(void * handle, const char * symbol) +{ +#if NV_OS_WIN32 || NV_OS_XBOX + return (void *)GetProcAddress((HMODULE)handle, symbol); +#else + return (void *)dlsym(handle, symbol); +#endif +} diff --git a/src/nvcore/Library.h b/src/nvcore/Library.h new file mode 100644 index 0000000..999e662 --- /dev/null +++ b/src/nvcore/Library.h @@ -0,0 +1,51 @@ +// This code is in the public domain -- castano@gmail.com + +#pragma once +#ifndef NV_CORE_LIBRARY_H +#define NV_CORE_LIBRARY_H + +#include "nvcore.h" + +#if NV_OS_WIN32 +#define LIBRARY_NAME(name) #name ".dll" +#elif NV_OS_DARWIN +#define NV_LIBRARY_NAME(name) "lib" #name ".dylib" +#else +#define NV_LIBRARY_NAME(name) "lib" #name ".so" +#endif + +NVCORE_API void * nvLoadLibrary(const char * name); +NVCORE_API void nvUnloadLibrary(void * lib); +NVCORE_API void * nvBindSymbol(void * lib, const char * symbol); + +class NVCORE_CLASS Library +{ +public: + Library(const char * name) + { + handle = nvLoadLibrary(name); + } + ~Library() + { + if (isValid()) + { + nvUnloadLibrary(handle); + } + } + + bool isValid() const + { + return handle != NULL; + } + + void * bindSymbol(const char * symbol) + { + return nvBindSymbol(handle, symbol); + } + +private: + void * handle; +}; + + +#endif // NV_CORE_LIBRARY_H