From 9d6fbddfd031852f7c6d1a10aff9fa5ef690858b Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 3 Apr 2020 13:33:26 +0200
Subject: [PATCH 1/2] Don't call Console APIs on Winstore builds

The API's are only available on desktop builds.
https://docs.microsoft.com/en-us/windows/console/getstdhandle
https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo
https://docs.microsoft.com/en-us/windows/console/writeconsole

Instead send logs to the debug output
---
 src/share/win_utf8_io/win_utf8_io.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c
index bbb6a74a..1e0c1e86 100644
--- a/src/share/win_utf8_io/win_utf8_io.c
+++ b/src/share/win_utf8_io/win_utf8_io.c
@@ -34,6 +34,7 @@
 #endif
 
 #include <windows.h>
+#include <winapifamily.h>
 #include "share/win_utf8_io.h"
 #include "share/windows_unicode_filenames.h"
 
@@ -182,11 +183,13 @@ size_t strlen_utf8(const char *str)
 int win_get_console_width(void)
 {
 	int width = 80;
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
 	CONSOLE_SCREEN_BUFFER_INFO csbi;
 	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
 	if(hOut != INVALID_HANDLE_VALUE && hOut != NULL)
 		if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0)
 			width = csbi.dwSize.X;
+#endif
 	return width;
 }
 
@@ -194,6 +197,10 @@ int win_get_console_width(void)
 
 static int wprint_console(FILE *stream, const wchar_t *text, size_t len)
 {
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+	(void)stream;
+	OutputDebugStringW(text);
+#else
 	DWORD out;
 	int ret;
 
@@ -219,6 +226,7 @@ static int wprint_console(FILE *stream, const wchar_t *text, size_t len)
 	ret = fputws(text, stream);
 	if (ret < 0)
 		return ret;
+#endif
 	return len;
 }
 
-- 
2.26.0.windows.1

