eizoctl: fix message formatting on Windows

This increases the binary size, but at least we stop showing
Chinese characters instead of ASCII.
This commit is contained in:
Přemysl Eric Janouch 2025-01-18 20:27:44 +01:00
parent 2594f8467d
commit dab190e857
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -18,6 +18,14 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
*/ */
// On Windows, vswprintf() interprets %s in the width of the format string,
// and %hs is not really compliant with any standard:
// https://devblogs.microsoft.com/oldnewthing/20190830-00/?p=102823
#ifdef _WIN32
#define __USE_MINGW_ANSI_STDIO
#endif
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -41,7 +49,9 @@
#define hid_init hidapi_hid_init #define hid_init hidapi_hid_init
#endif #endif
#if defined __GNUC__ #if defined __MINGW_GNU_PRINTF
#define ATTRIBUTE_PRINTF(x, y) __MINGW_GNU_PRINTF((x), (y))
#elif defined __GNUC__
#define ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y))) #define ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y)))
#else #else
#define ATTRIBUTE_PRINTF(x, y) #define ATTRIBUTE_PRINTF(x, y)
@ -1241,8 +1251,8 @@ message_output(const char *format, ...)
wchar_t *message = message_printf(format, ap); wchar_t *message = message_printf(format, ap);
va_end(ap); va_end(ap);
if (message) { if (message) {
MessageBox( MessageBox(NULL, message,
NULL, message, NULL, MB_ICONINFORMATION | MB_OK | MB_APPLMODAL); L"Message", MB_ICONINFORMATION | MB_OK | MB_APPLMODAL);
free(message); free(message);
} }
} }