diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-09-16 19:56:57 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-09-16 19:56:57 +0200 |
commit | 8ccd8e6ba36fca2504ef7da35956a5a4a81aedcb (patch) | |
tree | 0b19960d2d9a74ec9127d71c95a294972c90cbe2 /src | |
parent | 32775e64bab47dc798f7d62953f93840acdcfa02 (diff) |
Adding debug messages while loading DLLs.
Diffstat (limited to 'src')
-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; } |