From 8ccd8e6ba36fca2504ef7da35956a5a4a81aedcb Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 16 Sep 2010 19:56:57 +0200 Subject: Adding debug messages while loading DLLs. --- src/lua-plugin.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src') 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 #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; } -- cgit v1.2.3