diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2011-10-03 23:21:16 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2011-10-03 23:21:16 +0200 |
commit | 322028a0e81c60296ce0ed7b0beef0737db0428c (patch) | |
tree | 290a604937688b82dbd96a1d62cfea75b1758221 | |
parent | 41bb9104804fa6f75e8862a1240c705d4fb29412 (diff) | |
parent | 8ccd8e6ba36fca2504ef7da35956a5a4a81aedcb (diff) |
Merge branch 'master' of /pub/repo.git/lua-modules
-rw-r--r-- | src/lua-plugin.cc | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/lua-plugin.cc b/src/lua-plugin.cc index bf5fc29..8ff67ee 100644 --- a/src/lua-plugin.cc +++ b/src/lua-plugin.cc @@ -15,14 +15,35 @@ typedef void(*init_ptr_t)(Lua *); #include <windows.h> #include "MemoryModule.h" +static void showError() { + DWORD dwErrCode = GetLastError(); + LPVOID lpMsgBuf; + if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, 0, NULL )) { + Base::printm(M_INFO, "Error: %s\n", lpMsgBuf); + LocalFree(lpMsgBuf); + } +} + +static HMODULE LoadLibraryExWrap(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags) { + HMODULE r = LoadLibraryEx(lpFileName, hFile, dwFlags); + if (!r) + showError(); + return r; +} + void LuaLoadPlugin(const String & _fname, const String & searchpath, Lua * L) throw (GeneralException) { HMODULE handle; String fname = _fname + "." SHARED_EXT; Base::printm(M_INFO, "Loading library " + fname + "\n"); - if (!(handle = LoadLibraryEx(fname.to_charp(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) && - !(handle = LoadLibraryEx(fname.to_charp(), NULL, NULL))) { + if (!(handle = LoadLibraryExWrap(fname.to_charp(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) && + !(handle = LoadLibraryExWrap(fname.to_charp(), NULL, NULL))) { LuaLoadPlugin(&Input(fname), L); return; } |