You never want to blindly switch between widechar and ANSI functions

This commit is contained in:
Randy Heit 2015-04-26 20:53:16 -05:00
parent 0380ba642b
commit 68e43fe65d
2 changed files with 7 additions and 12 deletions

View File

@ -1601,19 +1601,19 @@ unsigned int I_MakeRNGSeed()
FString I_GetLongPathName(FString shortpath) FString I_GetLongPathName(FString shortpath)
{ {
static TOptWin32Proc<DWORD (WINAPI*)(LPCTSTR, LPTSTR, DWORD)> static TOptWin32Proc<DWORD (WINAPI*)(LPCTSTR, LPTSTR, DWORD)>
GetLongPathName("kernel32.dll", "GetLongPathNameA", NULL); GetLongPathNameA("kernel32.dll", "GetLongPathNameA");
// Doesn't exist on NT4 // Doesn't exist on NT4
if (GetLongPathName == NULL) if (GetLongPathName == NULL)
return shortpath; return shortpath;
DWORD buffsize = GetLongPathName.Call(shortpath.GetChars(), NULL, 0); DWORD buffsize = GetLongPathNameA.Call(shortpath.GetChars(), NULL, 0);
if (buffsize == 0) if (buffsize == 0)
{ // nothing to change (it doesn't exist, maybe?) { // nothing to change (it doesn't exist, maybe?)
return shortpath; return shortpath;
} }
TCHAR *buff = new TCHAR[buffsize]; TCHAR *buff = new TCHAR[buffsize];
DWORD buffsize2 = GetLongPathName.Call(shortpath.GetChars(), buff, buffsize); DWORD buffsize2 = GetLongPathNameA.Call(shortpath.GetChars(), buff, buffsize);
if (buffsize2 >= buffsize) if (buffsize2 >= buffsize)
{ // Failure! Just return the short path { // Failure! Just return the short path
delete[] buff; delete[] buff;

View File

@ -56,25 +56,20 @@ extern os_t OSPlatform;
template<typename Proto> template<typename Proto>
class TOptWin32Proc class TOptWin32Proc
{ {
static Proto GetOptionalWin32Proc(const char* module, const char* function, const char* alt) static Proto GetOptionalWin32Proc(const char* module, const char* function)
{ {
HMODULE hmodule = GetModuleHandle(module); HMODULE hmodule = GetModuleHandle(module);
if (hmodule == NULL) if (hmodule == NULL)
return NULL; return NULL;
Proto ret = (Proto)GetProcAddress(hmodule, function); return (Proto)GetProcAddress(hmodule, function);
if(ret != NULL || alt == NULL)
return ret;
// Lookup alternate function name (ex. ProcW -> ProcA)
return (Proto)GetProcAddress(hmodule, alt);
} }
public: public:
const Proto Call; const Proto Call;
TOptWin32Proc(const char* module, const char* function, const char* alt=NULL) TOptWin32Proc(const char* module, const char* function)
: Call(GetOptionalWin32Proc(module, function, alt)) {} : Call(GetOptionalWin32Proc(module, function)) {}
// Wrapper object can be tested against NULL, but not directly called. // Wrapper object can be tested against NULL, but not directly called.
operator const void*() const { return Call; } operator const void*() const { return Call; }