Fix WriteConsole signature

This commit is contained in:
Victor Zverovich 2020-09-27 13:49:40 -07:00
parent 51f2e2ca27
commit 79694d424c
2 changed files with 16 additions and 5 deletions

View File

@ -2824,12 +2824,13 @@ FMT_FUNC std::string detail::vformat(string_view format_str, format_args args) {
#ifdef _WIN32 #ifdef _WIN32
namespace detail { namespace detail {
using dword = conditional_t<sizeof(long) == 8, unsigned, unsigned long>;
extern "C" int __stdcall WriteConsoleW(void* hConsoleOutput, extern "C" int __stdcall WriteConsoleW(void* hConsoleOutput,
const void* lpBuffer, const void* lpBuffer,
uint32_t nNumberOfCharsToWrite, dword nNumberOfCharsToWrite,
uint32_t* lpNumberOfCharsWritten, dword* lpNumberOfCharsWritten,
void* lpReserved); void* lpReserved);
} } // namespace detail
#endif #endif
FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { 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); auto fd = _fileno(f);
if (_isatty(fd)) { if (_isatty(fd)) {
detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size())); detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
auto written = uint32_t(); auto written = detail::dword();
if (!detail::WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)), if (!detail::WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)),
u16.c_str(), static_cast<uint32_t>(u16.size()), u16.c_str(), static_cast<uint32_t>(u16.size()),
&written, nullptr)) { &written, nullptr)) {

View File

@ -19,7 +19,10 @@
#include "gtest-extra.h" #include "gtest-extra.h"
#include "util.h" #include "util.h"
#undef max #ifdef _WIN32
# include <windows.h>
# undef max
#endif
using fmt::detail::bigint; using fmt::detail::bigint;
using fmt::detail::fp; using fmt::detail::fp;
@ -409,3 +412,10 @@ TEST(UtilTest, WriteFallbackUIntPtr) {
fmt::detail::fallback_uintptr(reinterpret_cast<void*>(0xface)), nullptr); fmt::detail::fallback_uintptr(reinterpret_cast<void*>(0xface)), nullptr);
EXPECT_EQ(s, "0xface"); EXPECT_EQ(s, "0xface");
} }
#ifdef _WIN32
TEST(UtilTest, WriteConsoleSignature) {
decltype(WriteConsoleW)* p = fmt::detail::WriteConsoleW;
(void)p;
}
#endif