2002-06-05 11:57:14 +02:00
|
|
|
/*
|
|
|
|
* mod_loader.cpp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../jrd/os/mod_loader.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
2002-11-17 16:46:24 +01:00
|
|
|
typedef Firebird::string string;
|
|
|
|
|
2002-06-05 11:57:14 +02:00
|
|
|
/// This is the Win32 implementation of the mod_loader abstraction.
|
|
|
|
|
|
|
|
class Win32Module : public ModuleLoader::Module
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Win32Module(HMODULE m) : module(m) {}
|
|
|
|
~Win32Module();
|
2002-11-17 16:46:24 +01:00
|
|
|
void *findSymbol(const string&);
|
2002-06-05 11:57:14 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
HMODULE module;
|
|
|
|
};
|
|
|
|
|
2002-11-17 16:46:24 +01:00
|
|
|
bool ModuleLoader::isLoadableModule(const string& module)
|
2002-06-05 11:57:14 +02:00
|
|
|
{
|
2003-03-14 12:28:10 +01:00
|
|
|
LPCSTR pszName = module.c_str();
|
|
|
|
HINSTANCE hMod = LoadLibraryEx(pszName, 0, LOAD_LIBRARY_AS_DATAFILE);
|
|
|
|
if (hMod) {
|
|
|
|
FreeLibrary((HMODULE)hMod);
|
|
|
|
}
|
|
|
|
return hMod != 0;
|
2002-06-05 11:57:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleLoader::doctorModuleExtention(Firebird::string& name)
|
|
|
|
{
|
2002-11-17 16:46:24 +01:00
|
|
|
string::size_type pos = name.rfind(".dll");
|
|
|
|
if (pos != string::npos && pos == name.length() - 4)
|
|
|
|
return;
|
2002-06-05 11:57:14 +02:00
|
|
|
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-17 16:46:24 +01:00
|
|
|
FARPROC result = GetProcAddress(module, symName.c_str());
|
2002-06-05 11:57:14 +02:00
|
|
|
if (!result)
|
|
|
|
{
|
2002-11-17 16:46:24 +01:00
|
|
|
string newSym = '_' + symName;
|
2002-06-05 11:57:14 +02:00
|
|
|
result = GetProcAddress(module, newSym.c_str());
|
|
|
|
}
|
2002-11-26 09:56:06 +01:00
|
|
|
return (void*) result;
|
2002-06-05 11:57:14 +02:00
|
|
|
}
|