Common: Require explicit handle validation

Using operator bool() hid ambiguity when handle was polymorfic with
bool. Using operator!() reqired !! to test for validity which results in
awkward code.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-06-12 14:04:17 +02:00
parent b04df162ae
commit 2147ed71ef

View File

@ -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);