]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dynamic.cpp
Update wiki links to use HTTPS and point to the correct pages.
[user/henk/code/inspircd.git] / src / dynamic.cpp
index b17f131904a165234fc7b69810af4ecf8daeefba..25178cfa111c7f287461e9fd4053e7f70e22cb0a 100644 (file)
@@ -43,11 +43,7 @@ DLLManager::DLLManager(const char *fname)
        h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
        if (!h)
        {
-#ifdef _WIN32
                RetrieveLastError();
-#else
-               err = dlerror();
-#endif
        }
 }
 
@@ -72,11 +68,7 @@ Module* DLLManager::CallInit()
        initfn.vptr = dlsym(h, MODULE_INIT_STR);
        if (!initfn.vptr)
        {
-#ifdef _WIN32
                RetrieveLastError();
-#else
-               err = dlerror();
-#endif
                return NULL;
        }
 
@@ -94,16 +86,21 @@ std::string DLLManager::GetVersion()
        return "Unversioned module";
 }
 
-#ifdef _WIN32
 void DLLManager::RetrieveLastError()
 {
-       CHAR errmsg[100];
-       FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errmsg, 100, 0);
+#if defined _WIN32
+       char errmsg[500];
+       DWORD dwErrorCode = GetLastError();
+       if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)errmsg, _countof(errmsg), NULL) == 0)
+               sprintf_s(errmsg, _countof(errmsg), "Error code: %u", dwErrorCode);
        SetLastError(ERROR_SUCCESS);
        err = errmsg;
+#else
+       char* errmsg = dlerror();
+       err = errmsg ? errmsg : "Unknown error";
+#endif
 
        std::string::size_type p;
        while ((p = err.find_last_of("\r\n")) != std::string::npos)
                err.erase(p, 1);
 }
-#endif