Files
LifeProject/LifeGraphics/Plugin.cpp
T

34 lines
1010 B
C++
Raw Normal View History

2025-05-13 02:46:21 +03:00
#include "Plugin.h"
#include <stdexcept>
namespace LifeGraphics
{
Plugin::Plugin(const std::string& fileName)
{
g_hDLL = ::LoadLibraryA(fileName.c_str());
if(!g_hDLL)
throw std::runtime_error("Could not load library");
try
{
g_pfnGetPluginVersion = reinterpret_cast<fn_getPluginVersion>(::GetProcAddress(g_hDLL, "getPluginVersion"));
g_pfnGetEngineVersion = reinterpret_cast<fn_getEngineVersion>(::GetProcAddress(g_hDLL, "getEngineVersion"));
g_pfnRegisterPlugin = reinterpret_cast<fn_registerPlugin>(::GetProcAddress(g_hDLL, "registerPlugin"));
//g_pfnGetPluginName = reinterpret_cast<fn_getPluginName>(::GetProcAddress(g_hDLL, "getPluginName"));
if(!g_pfnGetPluginVersion || !g_pfnGetEngineVersion || !g_pfnRegisterPlugin)
throw std::runtime_error("Plugin is not valid");
}
catch(...)
{
::FreeModule(g_hDLL);
throw std::runtime_error("Plugin is not valid");
}
}
Plugin::~Plugin()
{
if(g_referenceCount<=0 && g_hDLL != NULL)
::FreeModule(g_hDLL);
}
}