diff --git a/include/WinStd/WinHTTP.h b/include/WinStd/WinHTTP.h index 8d1a8a8b..e32c9a7e 100644 --- a/include/WinStd/WinHTTP.h +++ b/include/WinStd/WinHTTP.h @@ -212,7 +212,7 @@ namespace winstd last_error_saver last_error_save; std::wstring wstr; winstd::library winhttp(LoadLibraryW(L"WINHTTP.DLL")); - if (WINHTTP_ERROR_BASE < num && num <= WINHTTP_ERROR_LAST && winhttp && FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, (HMODULE)winhttp, num, dwLanguageId, wstr, NULL) || + if (WINHTTP_ERROR_BASE < num && num <= WINHTTP_ERROR_LAST && winhttp.valid() && FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, (HMODULE)winhttp, num, dwLanguageId, wstr, NULL) || FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, num, dwLanguageId, wstr, NULL)) { // Stock Windows error messages contain CRLF. Well... Trim all the trailing white space. wstr.erase(wstr.find_last_not_of(L" \t\n\r\f\v") + 1);