diff options
| -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;      } | 
