diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index d2a0b81a..ee72c61c 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2824,12 +2824,13 @@ FMT_FUNC std::string detail::vformat(string_view format_str, format_args args) { #ifdef _WIN32 namespace detail { +using dword = conditional_t; extern "C" int __stdcall WriteConsoleW(void* hConsoleOutput, const void* lpBuffer, - uint32_t nNumberOfCharsToWrite, - uint32_t* lpNumberOfCharsWritten, + dword nNumberOfCharsToWrite, + dword* lpNumberOfCharsWritten, void* lpReserved); -} +} // namespace detail #endif FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { @@ -2840,7 +2841,7 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { auto fd = _fileno(f); if (_isatty(fd)) { detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size())); - auto written = uint32_t(); + auto written = detail::dword(); if (!detail::WriteConsoleW(reinterpret_cast(_get_osfhandle(fd)), u16.c_str(), static_cast(u16.size()), &written, nullptr)) { diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index d77842da..b93a4c25 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -19,7 +19,10 @@ #include "gtest-extra.h" #include "util.h" -#undef max +#ifdef _WIN32 +# include +# undef max +#endif using fmt::detail::bigint; using fmt::detail::fp; @@ -409,3 +412,10 @@ TEST(UtilTest, WriteFallbackUIntPtr) { fmt::detail::fallback_uintptr(reinterpret_cast(0xface)), nullptr); EXPECT_EQ(s, "0xface"); } + +#ifdef _WIN32 +TEST(UtilTest, WriteConsoleSignature) { + decltype(WriteConsoleW)* p = fmt::detail::WriteConsoleW; + (void)p; +} +#endif