Codechange: replace lengthof with std::size in Windows specific code

This commit is contained in:
rubidium42
2024-04-10 20:12:33 +02:00
committed by rubidium42
parent 6bc4a62c27
commit 442daf58da
6 changed files with 17 additions and 17 deletions

View File

@@ -78,7 +78,7 @@ static std::string GetLastErrorAsString()
DWORD error_code = GetLastError();
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, GetModuleHandle(L"winhttp.dll"), error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, lengthof(buffer), nullptr) == 0) {
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, static_cast<DWORD>(std::size(buffer)), nullptr) == 0) {
return fmt::format("unknown error {}", error_code);
}
@@ -222,11 +222,11 @@ void NetworkHTTPRequest::Connect()
/* Convert the URL to its components. */
url_components.dwStructSize = sizeof(url_components);
url_components.lpszScheme = scheme;
url_components.dwSchemeLength = lengthof(scheme);
url_components.dwSchemeLength = static_cast<DWORD>(std::size(scheme));
url_components.lpszHostName = hostname;
url_components.dwHostNameLength = lengthof(hostname);
url_components.dwHostNameLength = static_cast<DWORD>(std::size(hostname));
url_components.lpszUrlPath = url_path;
url_components.dwUrlPathLength = lengthof(url_path);
url_components.dwUrlPathLength = static_cast<DWORD>(std::size(url_path));
WinHttpCrackUrl(this->uri.c_str(), 0, 0, &url_components);
/* Create the HTTP connection. */

View File

@@ -83,7 +83,7 @@ const std::string &NetworkError::AsString() const
#if defined(_WIN32)
wchar_t buffer[512];
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, this->error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, lengthof(buffer), nullptr) == 0) {
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, static_cast<DWORD>(std::size(buffer)), nullptr) == 0) {
this->message.assign(fmt::format("Unknown error {}", this->error));
} else {
this->message.assign(FS2OTTD(buffer));