Revision: 8299 https://osdn.net/projects/ttssh2/scm/svn/commits/8299 Author: zmatsuo Date: 2019-10-13 00:28:06 +0900 (Sun, 13 Oct 2019) Log Message: ----------- 9x系でダイアログの文字が表示されるよう修正 - GetPrivateProfileString() の仕様がOSによって異なっている - どのOSでも動作するようにした Modified Paths: -------------- branches/unicode_buf/teraterm/common/i18n.c -------------- next part -------------- Modified: branches/unicode_buf/teraterm/common/i18n.c =================================================================== --- branches/unicode_buf/teraterm/common/i18n.c 2019-10-12 07:46:02 UTC (rev 8298) +++ branches/unicode_buf/teraterm/common/i18n.c 2019-10-12 15:28:06 UTC (rev 8299) @@ -32,11 +32,14 @@ #include "compat_win.h" #include <assert.h> -#include <tchar.h> +/** + * GetI18nStr() \x82\xCC unicode\x94\xC5 + */ DllExport void WINAPI GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile) { + DWORD size; if (pGetPrivateProfileStringW != NULL) { wchar_t sectionW[64]; wchar_t keyW[128]; @@ -44,21 +47,38 @@ MultiByteToWideChar(CP_ACP, 0, section, -1, sectionW, _countof(sectionW)); MultiByteToWideChar(CP_ACP, 0, key, -1, keyW, _countof(keyW)); MultiByteToWideChar(CP_ACP, 0, iniFile, -1, iniFileW, _countof(iniFileW)); - pGetPrivateProfileStringW(sectionW, keyW, def, buf, buf_len, iniFileW); + size = pGetPrivateProfileStringW(sectionW, keyW, def, buf, buf_len, iniFileW); + if (size == 0 && def == NULL) { + buf[0] = 0; + } } else { char tmp[MAX_UIMSG]; char defA[MAX_UIMSG]; WideCharToMultiByte(CP_ACP, 0, def, -1, defA, _countof(defA), NULL, NULL); - GetPrivateProfileStringA(section, key, defA, tmp, _countof(tmp), iniFile); + size = GetPrivateProfileStringA(section, key, defA, tmp, _countof(tmp), iniFile); + if (size == 0 && def == NULL) { + buf[0] = 0; + } MultiByteToWideChar(CP_ACP, 0, tmp, -1, buf, buf_len); } RestoreNewLineW(buf); } +/** + * section/key\x82̕\xB6\x8E\x9A\x97\xF1\x82\xF0buf\x82ɃZ\x83b\x83g\x82\xB7\x82\xE9 + * section/key\x82\xAA\x8C\xA9\x82\xA9\x82\xE7\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ\x81A + * def\x82̕\xB6\x8E\x9A\x97\xF1\x82\xF0buf\x82ɃZ\x83b\x83g\x82\xB7\x82\xE9 + * def\x82\xAANULL\x82̏ꍇbuf[0] = 0\x82ƂȂ\xE9 + */ DllExport void WINAPI GetI18nStr(const char *section, const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile) { - GetPrivateProfileStringA(section, key, def, buf, buf_len, iniFile); + DWORD size = GetPrivateProfileStringA(section, key, def, buf, buf_len, iniFile); + if (size == 0 && def == NULL) { + // GetPrivateProfileStringA()\x82̖߂\xE8\x92l\x82\xCDbuf\x82ɃZ\x83b\x83g\x82\xB5\x82\xBD\x95\xB6\x8E\x9A\x90\x94(\x8FI\x92[\x8A܂܂\xB8) + // OS\x82̃o\x81[\x83W\x83\x87\x83\x93\x82ɂ\xE6\x82\xC1\x82Ă\xCDdef\x82\xAANULL\x82̎\x9E\x81Abuf\x82\xAA\x96\xA2\x90ݒ\xE8\x82ƂȂ邱\x82Ƃ\xAA\x82\xA0\x82\xE9 + buf[0] = 0; + } RestoreNewLine(buf); }