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 */
62 Module* DLLManager::CallInit()
68 initfn.vptr = dlsym(h, MODULE_INIT_STR);
75 return (*initfn.fptr)();
78 std::string DLLManager::GetVersion()
83 const char* srcver = (char*)dlsym(h, "inspircd_src_version");
89 void DLLManager::RetrieveLastError()
93 DWORD dwErrorCode = GetLastError();
94 if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)errmsg, _countof(errmsg), NULL) == 0)
95 sprintf_s(errmsg, _countof(errmsg), "Error code: %u", dwErrorCode);
96 SetLastError(ERROR_SUCCESS);
99 const char* errmsg = dlerror();
100 err = errmsg ? errmsg : "Unknown error";
103 std::string::size_type p;
104 while ((p = err.find_last_of("\r\n")) != std::string::npos)