From d77c894adcf98ee9894eb4a9765d0b40908c3585 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Thu, 11 May 2017 11:53:26 +0800 Subject: [PATCH] Add SharedLibrary Support --- MiniEngine.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ MiniEngine.h | 13 +++++++++++++ 2 files changed, 61 insertions(+) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 4b23056..283bcd6 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -1310,6 +1310,54 @@ namespace MiniEngine va_end(ap); } + SharedLibrary::SharedLibrary() + { + _obj=nullptr; + } + + SharedLibrary::SharedLibrary(const std::string& Filename) + { + _obj=nullptr; + load(Filename); + } + + SharedLibrary::~SharedLibrary() + { + if(_obj) + { + unload(); + } + } + + int SharedLibrary::load(const std::string& Filename) + { + if(_obj) return -1; + else + { + _obj=SDL_LoadObject(Filename.c_str()); + if(_obj) return 0; + else return -2; + } + } + + int SharedLibrary::unload() + { + if(_obj) + { + SDL_UnloadObject(_obj); + _obj=nullptr; + return 0; + } + else return -1; + } + + void* SharedLibrary::get(const std::string& FunctionName) + { + if(!_obj) return nullptr; + else return SDL_LoadFunction(_obj,FunctionName.c_str()); + } + + int SDLSystem::SDLInit() { return SDL_Init(SDL_INIT_EVERYTHING); diff --git a/MiniEngine.h b/MiniEngine.h index 387e007..4f09bc4 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -429,6 +429,19 @@ namespace MiniEngine static void critical(const char* fmt,...);/// Critical }; + class SharedLibrary + { + public: + SharedLibrary(); + SharedLibrary(const std::string& Filename); + ~SharedLibrary(); + int load(const std::string& Filename); + int unload(); + void* get(const std::string& FunctionName); + private: + void* _obj; + }; + class SDLSystem { public: