8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 20:43:03 +01:00
firebird-mirror/src/jrd/os/win32/mod_loader.cpp

69 lines
1.4 KiB
C++
Raw Normal View History

/*
* mod_loader.cpp
*
*/
#include "../jrd/os/mod_loader.h"
#include <windows.h>
2002-11-17 16:46:24 +01:00
typedef Firebird::string string;
/// 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&);
private:
HMODULE module;
};
2002-11-17 16:46:24 +01:00
bool ModuleLoader::isLoadableModule(const string& module)
{
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;
}
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;
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;
return FB_NEW(*getDefaultMemoryPool()) Win32Module(module);
}
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());
if (!result)
{
2002-11-17 16:46:24 +01:00
string newSym = '_' + symName;
result = GetProcAddress(module, newSym.c_str());
}
2002-11-26 09:56:06 +01:00
return (void*) result;
}