diff --git a/src/Http.c b/src/Http.c index 627873c18..b4060c533 100644 --- a/src/Http.c +++ b/src/Http.c @@ -640,13 +640,6 @@ static void Http_BackendFree(void) { #define UNICODE #define _UNICODE #endif - -#ifdef UNICODE -#define Platform_DecodeString(dst, src, len) String_AppendUtf16(dst, (cc_unichar*)(src), (len) * 2) -#else -#define Platform_DecodeString(dst, src, len) String_DecodeCP1252(dst, (cc_uint8*)(src), len) -#endif - #include #include static HINTERNET hInternet; @@ -745,13 +738,7 @@ static cc_result HttpCache_Lookup(struct HttpCacheEntry* e) { } cc_bool Http_DescribeError(cc_result res, cc_string* dst) { - TCHAR chars[600]; - res = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - GetModuleHandle(TEXT("wininet.dll")), res, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), chars, 600, NULL); - if (!res) return false; - - Platform_DecodeString(dst, chars, res); - return true; + return Platform_DescribeErrorExt(res, dst, GetModuleHandle(TEXT("wininet.dll"))); } static void Http_BackendInit(void) { diff --git a/src/Platform.c b/src/Platform.c index 18336d317..cf802624e 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -1614,15 +1614,22 @@ cc_result Platform_Decrypt(const cc_string* key, const void* data, int len, cc_s return 0; } -cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { +cc_bool Platform_DescribeErrorExt(cc_result res, cc_string* dst, void* lib) { TCHAR chars[NATIVE_STR_LEN]; - res = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, res, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), chars, NATIVE_STR_LEN, NULL); + DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; + if (lib) flags |= FORMAT_MESSAGE_FROM_HMODULE; + + res = FormatMessage(flags, lib, res, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + chars, NATIVE_STR_LEN, NULL); if (!res) return false; Platform_DecodeString(dst, chars, res); return true; } + +cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { + return Platform_DescribeErrorExt(res, dst, NULL); +} #elif defined CC_BUILD_POSIX int Platform_ConvertString(void* data, const cc_string* src) { cc_uint8* dst = (cc_uint8*)data; diff --git a/src/Platform.h b/src/Platform.h index 8fca2c3df..02b1f8a73 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -54,6 +54,7 @@ cc_result Platform_Decrypt(const cc_string* key, const void* data, int len, cc_s /* NOTE: This is for general functions like file I/O. If a more specific describe exists (e.g. Http_DescribeError), that should be preferred. */ cc_bool Platform_DescribeError(cc_result res, cc_string* dst); +cc_bool Platform_DescribeErrorExt(cc_result res, cc_string* dst, void* lib); /* Starts the game with the given arguments. */ CC_API cc_result Process_StartGame(const cc_string* args);