2002-06-05 11:57:14 +02:00
|
|
|
/*
|
|
|
|
* mod_loader.cpp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../jrd/os/mod_loader.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
/// This is the Win32 implementation of the mod_loader abstraction.
|
|
|
|
|
|
|
|
class Win32Module : public ModuleLoader::Module
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Win32Module(HMODULE m) : module(m) {}
|
|
|
|
~Win32Module();
|
|
|
|
void *findSymbol(const Firebird::string&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
HMODULE module;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool ModuleLoader::isLoadableModule(const Firebird::string& module)
|
|
|
|
{
|
|
|
|
return (GetModuleHandle(module.c_str()) || LoadLibrary(module.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleLoader::doctorModuleExtention(Firebird::string& name)
|
|
|
|
{
|
|
|
|
Firebird::string::size_type pos = name.rfind(".dll");
|
|
|
|
if (pos != Firebird::string::npos && pos == name.length() - 4)
|
|
|
|
return; // No doctoring necessary
|
|
|
|
name += ".dll";
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleLoader::Module *ModuleLoader::loadModule(const Firebird::string& modPath)
|
|
|
|
{
|
|
|
|
HMODULE module = GetModuleHandle(modPath.c_str());
|
|
|
|
if (!module)
|
|
|
|
module = LoadLibrary(modPath.c_str());
|
|
|
|
if (!module)
|
|
|
|
return 0;
|
|
|
|
|
2002-09-25 19:12:16 +02:00
|
|
|
return FB_NEW(*getDefaultMemoryPool()) Win32Module(module);
|
2002-06-05 11:57:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Win32Module::~Win32Module()
|
|
|
|
{
|
|
|
|
if (module)
|
|
|
|
FreeLibrary(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Win32Module::findSymbol(const Firebird::string& symName)
|
|
|
|
{
|
2002-11-14 14:40:04 +01:00
|
|
|
FARPROC result;
|
2002-06-05 11:57:14 +02:00
|
|
|
|
|
|
|
result = GetProcAddress(module, symName.c_str());
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
Firebird::string newSym = '_' + symName;
|
|
|
|
|
|
|
|
result = GetProcAddress(module, newSym.c_str());
|
|
|
|
}
|
2002-11-14 14:40:04 +01:00
|
|
|
return static_cast<void*>(result);
|
2002-06-05 11:57:14 +02:00
|
|
|
}
|