From 253d63159f79762ebd40aea0c20704cd29acb3c9 Mon Sep 17 00:00:00 2001 From: Bernd Baumanns Date: Sat, 26 Sep 2020 16:03:16 +0200 Subject: [PATCH] Remove dependency on windows.h (#1900) --- include/fmt/format-inl.h | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 788dafb8..d1279e70 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -23,16 +23,23 @@ #endif #ifdef _WIN32 -# if defined(FMT_BIG_WIN) || defined(NOMINMAX) -# include -# else -# define NOMINMAX -# define WIN32_LEAN_AND_MEAN -# include -# undef WIN32_LEAN_AND_MEAN -# undef NOMINMAX -# endif # include +FMT_BEGIN_NAMESPACE +namespace details { + +# if !defined(__LP64__) +using DWORD = unsigned long; +# else +using DWORD = unsigned int; +# endif +// WriteConsoleW should not become visible in global namespace +extern "C" { +int __stdcall WriteConsoleW(void* hConsoleOutput, const void* lpBuffer, + DWORD nNumberOfCharsToWrite, + DWORD* lpNumberOfCharsWritten, void* lpReserved); +} +} // namespace details +FMT_END_NAMESPACE #endif // Dummy implementations of strerror_r and strerror_s called if corresponding @@ -2897,10 +2904,10 @@ 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 = DWORD(); - if (!WriteConsoleW(reinterpret_cast(_get_osfhandle(fd)), - u16.c_str(), static_cast(u16.size()), &written, - nullptr)) { + auto written = details::DWORD(); + if (!details::WriteConsoleW( + reinterpret_cast(_get_osfhandle(fd)), u16.c_str(), + static_cast(u16.size()), &written, nullptr)) { FMT_THROW(format_error("failed to write to console")); } return;