google translate error handling

This commit is contained in:
Akash Mozumdar 2018-08-21 23:41:30 -04:00
parent 1312a80ddd
commit fffb63edf4

View File

@ -80,10 +80,13 @@ extern "C"
WinHttpReceiveResponse(request, NULL); WinHttpReceiveResponse(request, NULL);
WinHttpReadData(request, buffer, 10000, &bytesRead); WinHttpReadData(request, buffer, 10000, &bytesRead);
// Response formatted as JSON: starts with '[[["' // Response formatted as JSON: starts with '[[["'
if (buffer[0] == '[')
{
MultiByteToWideChar(CP_UTF8, 0, buffer + 4, (int)((strstr(buffer, "\",\"")) - (buffer + 4)), translation, 10000); MultiByteToWideChar(CP_UTF8, 0, buffer + 4, (int)((strstr(buffer, "\",\"")) - (buffer + 4)), translation, 10000);
message = translation; message = translation;
for (int i = -1; translation[++i];) if (translation[i] == L'\\') translation[i] = 0x200b; for (int i = -1; translation[++i];) if (translation[i] == L'\\') translation[i] = 0x200b;
} }
}
WinHttpCloseHandle(request); WinHttpCloseHandle(request);
} }
WinHttpCloseHandle(connection); WinHttpCloseHandle(connection);