编译lua,调用时出现unable to get ModulFileName

I have noticed that lua doesn't like when compiled with unicode in visual studio so i tracked down
the problem to loadlib.c and fixed it

line 101: DWORD n = GetModuleFileName(NULL, buff, nsize);
patched:
#ifdef UNICODE
 DWORD n = GetModuleFileNameA(NULL, buff, nsize);
#else
 DWORD n = GetModuleFileName(NULL, buff, nsize);
#endif


line 115-116:
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
     NULL, error, 0, buffer, sizeof(buffer), NULL))

patched:
#ifdef UNICODE
if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
     NULL, error, 0, buffer, sizeof(buffer), NULL))
#else
if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
     NULL, error, 0, buffer, sizeof(buffer), NULL))
#endif

line 128:
 HINSTANCE lib = LoadLibrary(path);

patched:
#ifdef UNICODE
 HINSTANCE lib = LoadLibraryA(path);
#else
 HINSTANCE lib = LoadLibrary(path);
#endif

The line numbers are from lua version 5.1.1. Basicly I use normal ascii version of the api function when using unicode mode. I also ifdeffed the normal' version if there is no unicode define because if someone is using old
version of win api (win 95?).



 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
原文地址: http://lua-users.org/lists/lua-l/2006-06/msg00427.html

你可能感兴趣的:(编译lua,调用时出现unable to get ModulFileName)