<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40514 >
Many Win32 API functions are actually macros nowadays that get mapped to either a function that expects string arguments in 8-bit ANSI/multibyte encoding (for example CP1252, but no UTF-8; see http://en.wikipedia.org/wiki/Windows_code_page) or a function that expects string arguments in 16-bit Unicode (UCS-2) encoding. Which function is chosen depends on the UNICODE/_UNICODE macros, which the developer needs to set for the target system. The reason for this function mapping is that these functions were originally 8-bit only and there was no real Unicode support before Windows NT and when real Unicode support was added with Windows NT, developers wanting to support all Windows versions shouldn't have to maintain two codebases that call different functions. Up until now Freeciv only supports the 8-bit/multibyte functions, because it always passes 8-bit/multibyte strings as arguments. But on Windows Mobile only the Unicode functions are available, so Freeciv should be able to work with those, too. The preferred way for Windows-only applications is to use the TCHAR* data type for all strings, which gets mapped to either char* or wchar_t*, depending on the UNICODE/_UNICODE macros, so the developer doesn't need to care about anything but passing the UNICODE/_UNICODE macros to the compiler. Using TCHAR* for every string is not applicable to Freeciv, of course, so a string conversion needs to be done where needed. That's what the attached patch does. There's also a library, libunicows (http://libunicows.sourceforge.net/ + http://opencow.sourceforge.net/), that provides some of the Unicode functions on Win9x. It converts the passed wide char strings to 8-bit/multibyte internally and calls the 8-bit/multibyte Win9x functions afterwards. If this library turns out to work well with Freeciv on Win9x and UNICODE/_UNICODE defined, we could always use the Unicode functions directly instead of the wrapper macros, which would make the conversion code a bit simpler (always convert to wide char then instead of doing different things depending on the UNICODE macro).
Index: client/civclient.c =================================================================== --- client/civclient.c (revision 15137) +++ client/civclient.c (working copy) @@ -212,7 +212,7 @@ /* Load win32 post-crash debugger */ #ifdef WIN32_NATIVE # ifndef NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary(TEXT("exchndl.dll")) == NULL) { # ifdef DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif Index: client/connectdlg_common.c =================================================================== --- client/connectdlg_common.c (revision 15137) +++ client/connectdlg_common.c (working copy) @@ -197,6 +197,8 @@ STARTUPINFO si; PROCESS_INFORMATION pi; + TCHAR tc_logfile[strlen(logfile) + 1]; + char savesdir[MAX_LEN_PATH]; char options[512]; char cmdline1[512]; @@ -286,7 +288,14 @@ # else # ifdef WIN32_NATIVE if (logfile) { - loghandle = CreateFile(logfile, GENERIC_WRITE, + +#ifdef UNICODE + mbstowcs(tc_logfile, logfile, strlen(logfile) + 1); +#else + sz_strlcpy(tc_logfile, logfile); +#endif + + loghandle = CreateFile(tc_logfile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); @@ -320,13 +329,27 @@ my_snprintf(cmdline2, sizeof(cmdline2), "./server/civserver %s", options); my_snprintf(cmdline3, sizeof(cmdline3), "civserver %s", options); - if (!CreateProcess(NULL, cmdline1, NULL, NULL, TRUE, + TCHAR tc_cmdline1[strlen(cmdline1) + 1]; + TCHAR tc_cmdline2[strlen(cmdline2) + 1]; + TCHAR tc_cmdline3[strlen(cmdline3) + 1]; + +#ifdef UNICODE + mbstowcs(tc_cmdline1, cmdline1, strlen(cmdline1) + 1); + mbstowcs(tc_cmdline2, cmdline2, strlen(cmdline2) + 1); + mbstowcs(tc_cmdline3, cmdline3, strlen(cmdline3) + 1); +#else + sz_strlcpy(tc_cmdline1, cmdline1); + sz_strlcpy(tc_cmdline2, cmdline2); + sz_strlcpy(tc_cmdline3, cmdline3); +#endif + + if (!CreateProcess(NULL, tc_cmdline1, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) - && !CreateProcess(NULL, cmdline2, NULL, NULL, TRUE, + && !CreateProcess(NULL, tc_cmdline2, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) - && !CreateProcess(NULL, cmdline3, NULL, NULL, TRUE, + && !CreateProcess(NULL, tc_cmdline3, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) { append_output_window(_("Couldn't start the server.")); Index: client/servers.c =================================================================== --- client/servers.c (revision 15137) +++ client/servers.c (working copy) @@ -200,6 +200,10 @@ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); + +#ifdef UNICODE + char _osname[wcslen(osvi.szCSDVersion) + 1]; +#endif switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32s: @@ -232,7 +236,13 @@ break; default: + +#ifdef UNICODE + wcstombs(_osname, osvi.szCSDVersion, sizeof(_osname)); + osname = _osname; +#else osname = osvi.szCSDVersion; +#endif break; } @@ -333,7 +343,15 @@ #ifdef WIN32_NATIVE char filename[MAX_PATH]; - GetTempPath(sizeof(filename), filename); + TCHAR tc_filename[MAX_PATH]; + GetTempPath(MAX_PATH, tc_filename); + +#ifdef UNICODE + wcstombs(filename, tc_filename, sizeof(filename)); +#else + sz_strlcpy(filename, tc_filename); +#endif + cat_snprintf(filename, sizeof(filename), "fctmp%d", myrand(1000)); scan->meta.fp = fopen(filename, "w+b"); Index: dependencies/lua/src/lib/loadlib.c =================================================================== --- dependencies/lua/src/lib/loadlib.c (revision 15137) +++ dependencies/lua/src/lib/loadlib.c (working copy) @@ -96,10 +96,16 @@ { int error=GetLastError(); char buffer[128]; + TCHAR tc_buffer[128]; if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, - 0, error, 0, buffer, sizeof(buffer), 0)) + 0, error, 0, tc_buffer, sizeof(buffer), 0)) { +#ifdef UNICODE + wcstombs(buffer, tc_buffer, sizeof(buffer)); +#else + strncpy(buffer, tc_buffer, sizeof(buffer)); +#endif lua_pushstring(L,buffer); - else + } else lua_pushfstring(L,"system error %d\n",error); } @@ -107,7 +113,15 @@ { const char *path=luaL_checkstring(L,1); const char *init=luaL_checkstring(L,2); - HINSTANCE lib=LoadLibrary(path); + + TCHAR tc_path[strlen(path) + 1]; +#ifdef UNICODE + mbstowcs(tc_path, path, strlen(path) + 1); +#else + strncpy(tc_path, path, sizeof(tc_path)); +#endif + + HINSTANCE lib=LoadLibrary(tc_path); if (lib!=NULL) { lua_CFunction f=(lua_CFunction) GetProcAddress(lib,init); Index: server/civserver.c =================================================================== --- server/civserver.c (revision 15137) +++ server/civserver.c (working copy) @@ -96,7 +96,7 @@ /* Load win32 post-crash debugger */ #ifdef WIN32_NATIVE # ifndef NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary(TEXT("exchndl.dll")) == NULL) { # ifdef DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif Index: utility/netintf.c =================================================================== --- utility/netintf.c (revision 15137) +++ utility/netintf.c (working copy) @@ -296,8 +296,16 @@ * of the current drive, which we may not have write access to. */ { char filename[MAX_PATH]; + TCHAR tc_filename[MAX_PATH]; - GetTempPath(sizeof(filename), filename); + GetTempPath(MAX_PATH, tc_filename); + +#ifdef UNICODE + wcstombs(filename, tc_filename, sizeof(filename)); +#else + sz_strlcpy(filename, tc_filename); +#endif + sz_strlcat(filename, "fctmp"); fp = fopen(filename, "w+b"); Index: utility/shared.c =================================================================== --- utility/shared.c (revision 15150) +++ utility/shared.c (working copy) @@ -783,20 +783,27 @@ * http://justcheckingonall.wordpress.com/2008/05/16/find-shell-folders-win32/ * http://archives.seul.org/or/cvs/Oct-2004/msg00082.html */ + TCHAR tc_home_dir[PATH_MAX]; LPITEMIDLIST pidl; LPMALLOC pMalloc; if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl))) { - home_dir = fc_malloc(PATH_MAX); - - if (!SUCCEEDED(SHGetPathFromIDList(pidl, home_dir))) { - free(home_dir); - home_dir = NULL; + if (!SUCCEEDED(SHGetPathFromIDList(pidl, tc_home_dir))) { freelog(LOG_ERROR, "Could not find home directory (SHGetPathFromIDList() failed)"); } + + /* got the path in tc_home_dir, now convert/copy to home_dir */ + home_dir = fc_malloc(PATH_MAX); + +#ifdef UNICODE + wcstombs(home_dir, tc_home_dir, PATH_MAX); +#else + mystrlcpy(home_dir, tc_home_dir, PATH_MAX); +#endif + SHGetMalloc(&pMalloc); if (pMalloc) { pMalloc->lpVtbl->Free(pMalloc, pidl); @@ -807,6 +814,7 @@ freelog(LOG_ERROR, "Could not find home directory (SHGetSpecialFolderLocation() failed)"); } + #else freelog(LOG_ERROR, "Could not find home directory (HOME is not set)"); home_dir = NULL; @@ -814,6 +822,7 @@ } init = TRUE; } + return home_dir; #endif } @@ -865,11 +874,15 @@ #ifdef WIN32_NATIVE /* On win32 the GetUserName function will give us the login name. */ { - char name[UNLEN + 1]; - DWORD length = sizeof(name); + DWORD length = UNLEN + 1; + TCHAR tc_name[length]; - if (GetUserName(name, &length)) { - mystrlcpy(buf, name, bufsz); + if (GetUserName(tc_name, &length)) { +#ifdef UNICODE + wcstombs(buf, tc_name, bufsz); +#else + mystrlcpy(buf, tc_name, bufsz); +#endif if (is_ascii_name(buf)) { freelog(LOG_VERBOSE, "GetUserName username is %s", buf); return buf; Index: utility/support.c =================================================================== --- utility/support.c (revision 15137) +++ utility/support.c (working copy) @@ -210,16 +210,24 @@ { #ifdef WIN32_NATIVE static char buf[256]; + TCHAR tc_buf[256]; long int error; error = GetLastError(); if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error, 0, buf, sizeof(buf), NULL)) { + NULL, error, 0, tc_buf, sizeof(buf), NULL)) { my_snprintf(buf, sizeof(buf), _("error %ld (failed FormatMessage)"), error); } +#ifdef UNICODE + wcstombs(buf, tc_buf, sizeof(buf)); +#else + strncpy(buf, tc_buf, sizeof(buf)); +#endif /* UNICODE */ return buf; -#else + +#else /* WIN32_NATIVE */ + #ifdef HAVE_STRERROR static char buf[256];
Index: client/civclient.c =================================================================== --- client/civclient.c (revision 15240) +++ client/civclient.c (working copy) @@ -213,7 +213,7 @@ /* Load win32 post-crash debugger */ #ifdef WIN32_NATIVE # ifndef NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary(TEXT("exchndl.dll")) == NULL) { # ifdef DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif Index: client/connectdlg_common.c =================================================================== --- client/connectdlg_common.c (revision 15240) +++ client/connectdlg_common.c (working copy) @@ -190,6 +190,8 @@ STARTUPINFO si; PROCESS_INFORMATION pi; + TCHAR tc_logfile[logfile ? strlen(logfile) + 1 : 1]; + char savesdir[MAX_LEN_PATH]; char options[512]; char cmdline1[512]; @@ -279,7 +281,14 @@ # else /* HAVE_WORKING_FORK */ # ifdef WIN32_NATIVE if (logfile) { - loghandle = CreateFile(logfile, GENERIC_WRITE, + +#ifdef UNICODE + mbstowcs(tc_logfile, logfile, strlen(logfile) + 1); +#else + sz_strlcpy(tc_logfile, logfile); +#endif + + loghandle = CreateFile(tc_logfile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); @@ -313,13 +322,27 @@ my_snprintf(cmdline2, sizeof(cmdline2), "./server/civserver %s", options); my_snprintf(cmdline3, sizeof(cmdline3), "civserver %s", options); - if (!CreateProcess(NULL, cmdline1, NULL, NULL, TRUE, + TCHAR tc_cmdline1[strlen(cmdline1) + 1]; + TCHAR tc_cmdline2[strlen(cmdline2) + 1]; + TCHAR tc_cmdline3[strlen(cmdline3) + 1]; + +#ifdef UNICODE + mbstowcs(tc_cmdline1, cmdline1, strlen(cmdline1) + 1); + mbstowcs(tc_cmdline2, cmdline2, strlen(cmdline2) + 1); + mbstowcs(tc_cmdline3, cmdline3, strlen(cmdline3) + 1); +#else + sz_strlcpy(tc_cmdline1, cmdline1); + sz_strlcpy(tc_cmdline2, cmdline2); + sz_strlcpy(tc_cmdline3, cmdline3); +#endif + + if (!CreateProcess(NULL, tc_cmdline1, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) - && !CreateProcess(NULL, cmdline2, NULL, NULL, TRUE, + && !CreateProcess(NULL, tc_cmdline2, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) - && !CreateProcess(NULL, cmdline3, NULL, NULL, TRUE, + && !CreateProcess(NULL, tc_cmdline3, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) { append_output_window(_("Couldn't start the server.")); Index: client/servers.c =================================================================== --- client/servers.c (revision 15240) +++ client/servers.c (working copy) @@ -202,6 +202,10 @@ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); + +#ifdef UNICODE + char _osname[wcslen(osvi.szCSDVersion) + 1]; +#endif switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32s: @@ -234,7 +238,13 @@ break; default: + +#ifdef UNICODE + wcstombs(_osname, osvi.szCSDVersion, sizeof(_osname)); + osname = _osname; +#else osname = osvi.szCSDVersion; +#endif break; } @@ -335,7 +345,15 @@ #ifdef WIN32_NATIVE char filename[MAX_PATH]; - GetTempPath(sizeof(filename), filename); + TCHAR tc_filename[MAX_PATH]; + GetTempPath(MAX_PATH, tc_filename); + +#ifdef UNICODE + wcstombs(filename, tc_filename, sizeof(filename)); +#else + sz_strlcpy(filename, tc_filename); +#endif + cat_snprintf(filename, sizeof(filename), "fctmp%d", myrand(1000)); scan->meta.fp = fopen(filename, "w+b"); Index: dependencies/lua/src/lib/loadlib.c =================================================================== --- dependencies/lua/src/lib/loadlib.c (revision 15240) +++ dependencies/lua/src/lib/loadlib.c (working copy) @@ -96,10 +96,16 @@ { int error=GetLastError(); char buffer[128]; + TCHAR tc_buffer[128]; if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, - 0, error, 0, buffer, sizeof(buffer), 0)) + 0, error, 0, tc_buffer, sizeof(buffer), 0)) { +#ifdef UNICODE + wcstombs(buffer, tc_buffer, sizeof(buffer)); +#else + strncpy(buffer, tc_buffer, sizeof(buffer)); +#endif lua_pushstring(L,buffer); - else + } else lua_pushfstring(L,"system error %d\n",error); } @@ -107,7 +113,15 @@ { const char *path=luaL_checkstring(L,1); const char *init=luaL_checkstring(L,2); - HINSTANCE lib=LoadLibrary(path); + + TCHAR tc_path[strlen(path) + 1]; +#ifdef UNICODE + mbstowcs(tc_path, path, strlen(path) + 1); +#else + strncpy(tc_path, path, sizeof(tc_path)); +#endif + + HINSTANCE lib=LoadLibrary(tc_path); if (lib!=NULL) { lua_CFunction f=(lua_CFunction) GetProcAddress(lib,init); Index: server/civserver.c =================================================================== --- server/civserver.c (revision 15240) +++ server/civserver.c (working copy) @@ -103,7 +103,7 @@ /* Load win32 post-crash debugger */ #ifdef WIN32_NATIVE # ifndef NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary(TEXT("exchndl.dll")) == NULL) { # ifdef DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif Index: utility/netintf.c =================================================================== --- utility/netintf.c (revision 15240) +++ utility/netintf.c (working copy) @@ -402,8 +402,16 @@ * of the current drive, which we may not have write access to. */ { char filename[MAX_PATH]; + TCHAR tc_filename[MAX_PATH]; - GetTempPath(sizeof(filename), filename); + GetTempPath(MAX_PATH, tc_filename); + +#ifdef UNICODE + wcstombs(filename, tc_filename, sizeof(filename)); +#else + sz_strlcpy(filename, tc_filename); +#endif + sz_strlcat(filename, "fctmp"); fp = fopen(filename, "w+b"); Index: utility/shared.c =================================================================== --- utility/shared.c (revision 15240) +++ utility/shared.c (working copy) @@ -801,20 +801,27 @@ * http://justcheckingonall.wordpress.com/2008/05/16/find-shell-folders-win32/ * http://archives.seul.org/or/cvs/Oct-2004/msg00082.html */ + TCHAR tc_home_dir[PATH_MAX]; LPITEMIDLIST pidl; LPMALLOC pMalloc; if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl))) { - home_dir = fc_malloc(PATH_MAX); - - if (!SUCCEEDED(SHGetPathFromIDList(pidl, home_dir))) { - free(home_dir); - home_dir = NULL; + if (!SUCCEEDED(SHGetPathFromIDList(pidl, tc_home_dir))) { freelog(LOG_ERROR, "Could not find home directory (SHGetPathFromIDList() failed)"); } + + /* got the path in tc_home_dir, now convert/copy to home_dir */ + home_dir = fc_malloc(PATH_MAX); + +#ifdef UNICODE + wcstombs(home_dir, tc_home_dir, PATH_MAX); +#else + mystrlcpy(home_dir, tc_home_dir, PATH_MAX); +#endif + SHGetMalloc(&pMalloc); if (pMalloc) { pMalloc->lpVtbl->Free(pMalloc, pidl); @@ -825,6 +832,7 @@ freelog(LOG_ERROR, "Could not find home directory (SHGetSpecialFolderLocation() failed)"); } + #else freelog(LOG_ERROR, "Could not find home directory (HOME is not set)"); home_dir = NULL; @@ -832,6 +840,7 @@ } init = TRUE; } + return home_dir; #endif } @@ -883,11 +892,15 @@ #ifdef WIN32_NATIVE /* On win32 the GetUserName function will give us the login name. */ { - char name[UNLEN + 1]; - DWORD length = sizeof(name); + DWORD length = UNLEN + 1; + TCHAR tc_name[length]; - if (GetUserName(name, &length)) { - mystrlcpy(buf, name, bufsz); + if (GetUserName(tc_name, &length)) { +#ifdef UNICODE + wcstombs(buf, tc_name, bufsz); +#else + mystrlcpy(buf, tc_name, bufsz); +#endif if (is_ascii_name(buf)) { freelog(LOG_VERBOSE, "GetUserName username is %s", buf); return buf; Index: utility/support.c =================================================================== --- utility/support.c (revision 15240) +++ utility/support.c (working copy) @@ -244,16 +244,24 @@ { #ifdef WIN32_NATIVE static char buf[256]; + TCHAR tc_buf[256]; long int error; error = GetLastError(); if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error, 0, buf, sizeof(buf), NULL)) { + NULL, error, 0, tc_buf, sizeof(buf), NULL)) { my_snprintf(buf, sizeof(buf), _("error %ld (failed FormatMessage)"), error); } +#ifdef UNICODE + wcstombs(buf, tc_buf, sizeof(buf)); +#else + strncpy(buf, tc_buf, sizeof(buf)); +#endif /* UNICODE */ return buf; -#else + +#else /* WIN32_NATIVE */ + #ifdef HAVE_STRERROR static char buf[256];
Index: client/civclient.c =================================================================== --- client/civclient.c (revision 15240) +++ client/civclient.c (working copy) @@ -181,7 +181,7 @@ /* Load win32 post-crash debugger */ #ifdef WIN32_NATIVE # ifndef NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary(TEXT("exchndl.dll")) == NULL) { # ifdef DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif Index: client/clinet.c =================================================================== --- client/clinet.c (revision 15240) +++ client/clinet.c (working copy) @@ -430,6 +462,10 @@ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); +#ifdef UNICODE + char _osname[wcslen(osvi.szCSDVersion) + 1]; +#endif + switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32s: osname = "Win32s"; @@ -461,7 +497,13 @@ break; default: - osname = osvi.szCSDVersion; + +#ifdef UNICODE + wcstombs(_osname, osvi.szCSDVersion, sizeof(_osname)); + osname = _osname; +#else + osname = osvi.szCSDVersion; +#endif break; } Index: client/connectdlg_common.c =================================================================== --- client/connectdlg_common.c (revision 15240) +++ client/connectdlg_common.c (working copy) @@ -196,6 +196,8 @@ STARTUPINFO si; PROCESS_INFORMATION pi; + TCHAR tc_logfile[logfile ? strlen(logfile) + 1 : 1]; + char savesdir[MAX_LEN_PATH]; char options[512]; char cmdline1[512]; @@ -285,7 +287,14 @@ # else # ifdef WIN32_NATIVE if (logfile) { - loghandle = CreateFile(logfile, GENERIC_WRITE, + +#ifdef UNICODE + mbstowcs(tc_logfile, logfile, strlen(logfile) + 1); +#else + sz_strlcpy(tc_logfile, logfile); +#endif + + loghandle = CreateFile(tc_logfile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); @@ -319,13 +328,27 @@ my_snprintf(cmdline2, sizeof(cmdline2), "./server/civserver %s", options); my_snprintf(cmdline3, sizeof(cmdline3), "civserver %s", options); - if (!CreateProcess(NULL, cmdline1, NULL, NULL, TRUE, + TCHAR tc_cmdline1[strlen(cmdline1) + 1]; + TCHAR tc_cmdline2[strlen(cmdline2) + 1]; + TCHAR tc_cmdline3[strlen(cmdline3) + 1]; + +#ifdef UNICODE + mbstowcs(tc_cmdline1, cmdline1, strlen(cmdline1) + 1); + mbstowcs(tc_cmdline2, cmdline2, strlen(cmdline2) + 1); + mbstowcs(tc_cmdline3, cmdline3, strlen(cmdline3) + 1); +#else + sz_strlcpy(tc_cmdline1, cmdline1); + sz_strlcpy(tc_cmdline2, cmdline2); + sz_strlcpy(tc_cmdline3, cmdline3); +#endif + + if (!CreateProcess(NULL, tc_cmdline1, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) - && !CreateProcess(NULL, cmdline2, NULL, NULL, TRUE, + && !CreateProcess(NULL, tc_cmdline2, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) - && !CreateProcess(NULL, cmdline3, NULL, NULL, TRUE, + && !CreateProcess(NULL, tc_cmdline3, NULL, NULL, TRUE, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) { append_output_window(_("Couldn't start the server.")); Index: server/civserver.c =================================================================== --- server/civserver.c (revision 15240) +++ server/civserver.c (working copy) @@ -61,7 +61,7 @@ /* Load win32 post-crash debugger */ #ifdef WIN32_NATIVE # ifndef NDEBUG - if (LoadLibrary("exchndl.dll") == NULL) { + if (LoadLibrary(TEXT("exchndl.dll")) == NULL) { # ifdef DEBUG fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n"); # endif Index: utility/netintf.c =================================================================== --- utility/netintf.c (revision 15240) +++ utility/netintf.c (working copy) @@ -219,8 +219,16 @@ * of the current drive, which we may not have write access to. */ { char filename[MAX_PATH]; + TCHAR tc_filename[MAX_PATH]; - GetTempPath(sizeof(filename), filename); + GetTempPath(MAX_PATH, tc_filename); + +#ifdef UNICODE + wcstombs(filename, tc_filename, sizeof(filename)); +#else + sz_strlcpy(filename, tc_filename); +#endif + sz_strlcat(filename, "fctmp"); fp = fopen(filename, "w+b"); Index: utility/shared.c =================================================================== --- utility/shared.c (revision 15240) +++ utility/shared.c (working copy) @@ -705,20 +705,27 @@ * http://justcheckingonall.wordpress.com/2008/05/16/find-shell-folders-win32/ * http://archives.seul.org/or/cvs/Oct-2004/msg00082.html */ + TCHAR tc_home_dir[PATH_MAX]; LPITEMIDLIST pidl; LPMALLOC pMalloc; if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl))) { - home_dir = fc_malloc(PATH_MAX); - - if (!SUCCEEDED(SHGetPathFromIDList(pidl, home_dir))) { - free(home_dir); - home_dir = NULL; + if (!SUCCEEDED(SHGetPathFromIDList(pidl, tc_home_dir))) { freelog(LOG_ERROR, "Could not find home directory (SHGetPathFromIDList() failed)"); } + + /* got the path in tc_home_dir, now convert/copy to home_dir */ + home_dir = fc_malloc(PATH_MAX); + +#ifdef UNICODE + wcstombs(home_dir, tc_home_dir, PATH_MAX); +#else + mystrlcpy(home_dir, tc_home_dir, PATH_MAX); +#endif + SHGetMalloc(&pMalloc); if (pMalloc) { pMalloc->lpVtbl->Free(pMalloc, pidl); @@ -729,6 +736,7 @@ freelog(LOG_ERROR, "Could not find home directory (SHGetSpecialFolderLocation() failed)"); } + #else freelog(LOG_ERROR, "Could not find home directory (HOME is not set)"); home_dir = NULL; @@ -736,6 +744,7 @@ } init = TRUE; } + return home_dir; #endif } @@ -794,11 +803,15 @@ #ifdef WIN32_NATIVE /* On win32 the GetUserName function will give us the login name. */ { - char name[UNLEN + 1]; - DWORD length = sizeof(name); + DWORD length = UNLEN + 1; + TCHAR tc_name[length]; - if (GetUserName(name, &length)) { - sz_strlcpy(username, name); + if (GetUserName(tc_name, &length)) { +#ifdef UNICODE + wcstombs(username, tc_name, sizeof(username)); +#else + sz_strlcpy(username, tc_name); +#endif if (is_ascii_name(username)) { freelog(LOG_VERBOSE, "GetUserName username is %s", username); return username; Index: utility/support.c =================================================================== --- utility/support.c (revision 15240) +++ utility/support.c (working copy) @@ -138,16 +138,24 @@ { #ifdef WIN32_NATIVE static char buf[256]; + TCHAR tc_buf[256]; long int error; error = GetLastError(); if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error, 0, buf, sizeof(buf), NULL)) { + NULL, error, 0, tc_buf, sizeof(buf), NULL)) { my_snprintf(buf, sizeof(buf), _("error %ld (failed FormatMessage)"), error); } +#ifdef UNICODE + wcstombs(buf, tc_buf, sizeof(buf)); +#else + strncpy(buf, tc_buf, sizeof(buf)); +#endif /* UNICODE */ return buf; -#else + +#else /* WIN32_NATIVE */ + #ifdef HAVE_STRERROR return strerror(errno); #else
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev