2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Oliver Lupton <oliverlupton@gmail.com>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2003, 2006 Craig Edwards <craigedwards@brainbox.cc>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #define dlopen(path, state) (void*)LoadLibraryA(path)
30 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
31 #define dlclose(handle) FreeLibrary((HMODULE)handle)
34 DLLManager::DLLManager(const char *fname)
36 if (!strstr(fname,".so"))
38 err = "This doesn't look like a module file to me...";
43 h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
50 DLLManager::~DLLManager()
52 /* close the library */
57 Module* DLLManager::CallInit()
65 vptr = GetSymbol(MODULE_INIT_STR);
72 void* DLLManager::GetSymbol(const char* name)
74 return h ? dlsym(h, name) : NULL;
77 std::string DLLManager::GetVersion()
79 const char* srcver = static_cast<const char*>(GetSymbol("inspircd_src_version"));
80 return srcver ? srcver : "";
83 void DLLManager::RetrieveLastError()
87 DWORD dwErrorCode = GetLastError();
88 if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)errmsg, _countof(errmsg), NULL) == 0)
89 sprintf_s(errmsg, _countof(errmsg), "Error code: %u", dwErrorCode);
90 SetLastError(ERROR_SUCCESS);
93 const char* errmsg = dlerror();
94 err = errmsg ? errmsg : "Unknown error";
97 std::string::size_type p;
98 while ((p = err.find_last_of("\r\n")) != std::string::npos)