summaryrefslogtreecommitdiff
path: root/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-11-20 20:12:02 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-11-29 16:29:54 +0100
commit727bd94560ca9056cdbe40fe2e7923ed008b6eac (patch)
treef0d202b6c72415751445bfd91f29dd96fe3f59d2 /src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
parenta0e4a3fd5d028694e9fa74d2de55eb4f3c3f14b0 (diff)
Add commandline conversion for Windows (no-op on other platforms)
- add Fl::args_to_utf8() to convert commandline arguments to UTF-8 This new function closes the gap that previously only Visual Studio applications converted their commandlines to UTF-8. Tested with MinGW, MSYS2/MinGW-w64, and Visual Studio (2019).
Diffstat (limited to 'src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx')
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
index faf89e979..d7b01465a 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -299,6 +299,40 @@ int Fl_WinAPI_System_Driver::rename(const char *fnam, const char *newnam) {
return _wrename(wbuf, wbuf1);
}
+// See Fl::args_to_utf8()
+int Fl_WinAPI_System_Driver::args_to_utf8(int argc, char ** &argv) {
+ int i;
+ char strbuf[2048]; // FIXME: allocate argv and strings dynamically
+
+ // Convert the command line arguments to UTF-8
+ LPWSTR *wideArgv = CommandLineToArgvW(GetCommandLineW(), &argc);
+ argv = (char **)malloc((argc + 1) * sizeof(char *));
+ for (i = 0; i < argc; i++) {
+ int ret = WideCharToMultiByte(CP_UTF8, // CodePage
+ 0, // dwFlags
+ wideArgv[i], // lpWideCharStr
+ -1, // cchWideChar
+ strbuf, // lpMultiByteStr
+ sizeof(strbuf), // cbMultiByte
+ NULL, // lpDefaultChar
+ NULL); // lpUsedDefaultChar
+
+ if (!ret)
+ strbuf[0] = '\0'; // return empty string
+ argv[i] = fl_strdup(strbuf);
+ }
+ argv[argc] = NULL; // required NULL pointer at end of list
+
+ // Free the wide character string array
+ LocalFree(wideArgv);
+
+ // Note: the allocated memory or argv[] will not be free'd by the system
+ // on exit. This does not constitute a memory leak.
+
+ return argc;
+}
+
+
// Two Windows-specific functions fl_utf8_to_locale() and fl_locale_to_utf8()
// from file fl_utf8.cxx are put here for API compatibility