# HG changeset patch # User Andre Heinecke # Date 1411047828 -7200 # Node ID ffdc8cba139a8adf7ddf4caf857c1e2dcbd2098d # Parent fd7d04bb37cb7af2f42815c8db965849bdef7ecb (issue36) Add acp_to_wchar based on utf8_to_wchar diff -r fd7d04bb37cb -r ffdc8cba139a common/strhelp.c --- a/common/strhelp.c Thu Sep 18 15:43:22 2014 +0200 +++ b/common/strhelp.c Thu Sep 18 15:43:48 2014 +0200 @@ -281,4 +281,29 @@ result[n] = 0; return result; } + +wchar_t +*acp_to_wchar (const char *string, size_t len) +{ + int n, ilen; + wchar_t *result; + + ilen = (int) len; + if (ilen < 0) + return NULL; + + n = MultiByteToWideChar (CP_ACP, 0, string, ilen, NULL, 0); + if (n < 0 || n + 1 < 0) + return NULL; + + result = xmalloc ((size_t)(n+1) * sizeof *result); + n = MultiByteToWideChar (CP_ACP, 0, string, ilen, result, n); + if (n < 0) + { + xfree (result); + return NULL; + } + result[n] = 0; + return result; +} #endif diff -r fd7d04bb37cb -r ffdc8cba139a common/strhelp.h --- a/common/strhelp.h Thu Sep 18 15:43:22 2014 +0200 +++ b/common/strhelp.h Thu Sep 18 15:43:48 2014 +0200 @@ -132,6 +132,16 @@ **/ wchar_t *utf8_to_wchar (const char *string, size_t len); +/** @brief convert a local 8 bit (acp) string to utf16 wchar + * + * @param[in] string acp string. Must be at least len characters long. + * @param[in] len number of characters to be converted. + * + * @returns pointer to a newly allocated wchar array. NULL on error. + * + **/ +wchar_t *acp_to_wchar (const char *string, size_t len); + /** @brief convert a utf16 string to utf8 * * @param[in] string utf16 string. Must be at least len characters long. diff -r fd7d04bb37cb -r ffdc8cba139a packaging/desktopshellrun.cpp --- a/packaging/desktopshellrun.cpp Thu Sep 18 15:43:22 2014 +0200 +++ b/packaging/desktopshellrun.cpp Thu Sep 18 15:43:48 2014 +0200 @@ -273,7 +273,9 @@ goto done; } - wbuf = utf8_to_wchar((*stacktop)->text, strlen((*stacktop)->text)); + /* For unicodensis this has to be utf8 to wchar */ + + wbuf = acp_to_wchar((*stacktop)->text, strlen((*stacktop)->text)); if (!wbuf) { ERRORPRINTF ("Failed to convert argument to wchar. error = 0x%lx.", hr); @@ -282,7 +284,7 @@ if ((*stacktop)->next && (*stacktop)->next->text) { - params = utf8_to_wchar((*stacktop)->next->text, strlen((*stacktop)->next->text)); + params = acp_to_wchar((*stacktop)->next->text, strlen((*stacktop)->next->text)); } if (!shellexecute(shellDispatch, wbuf, params))