Add SharedLibrary Support

This commit is contained in:
Kirigaya Kazuto 2017-05-11 11:53:26 +08:00
parent d8d77a5bd2
commit d77c894adc
2 changed files with 61 additions and 0 deletions

View File

@ -1310,6 +1310,54 @@ namespace MiniEngine
va_end(ap); 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() int SDLSystem::SDLInit()
{ {
return SDL_Init(SDL_INIT_EVERYTHING); return SDL_Init(SDL_INIT_EVERYTHING);

View File

@ -429,6 +429,19 @@ namespace MiniEngine
static void critical(const char* fmt,...);/// Critical 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 class SDLSystem
{ {
public: public: