From a18318ec0d9c3e01d21bda57b19eccf39717618b Mon Sep 17 00:00:00 2001 From: Yu-Chen Lin Date: Sun, 23 Oct 2022 14:15:25 +0800 Subject: [PATCH] Support wchar_t in argv in windows Fix #2932 Signed-off-by: Yu-Chen Lin --- app/src/main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main.c b/app/src/main.c index 3334cbf9dd..b3d0f12e58 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -4,6 +4,10 @@ #include #include #include +#ifdef __WINDOWS__ +#include +#include "util/str.h" +#endif #ifdef HAVE_V4L2 # include #endif @@ -20,6 +24,17 @@ int main(int argc, char *argv[]) { #ifdef __WINDOWS__ + int wargc; + wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &wargc); + + if (argc != wargc) { + return SCRCPY_EXIT_FAILURE; + } + + for (int i = 0; i < wargc; ++i) { + argv[i] = sc_str_from_wchars(wargv[i]); + } + // disable buffering, we want logs immediately // even line buffering (setvbuf() with mode _IOLBF) is not sufficient setbuf(stdout, NULL);