diff options
Diffstat (limited to 'src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx')
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 34 |
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 |
