Revision: 9420 https://osdn.net/projects/ttssh2/scm/svn/commits/9420 Author: zmatsuo Date: 2021-09-14 00:20:06 +0900 (Tue, 14 Sep 2021) Log Message: ----------- 文字長 MAX_PATH 以上の文字列を返せるよう doSelectFolderW() の仕様を変更 - 従来の doSelectFolder() を使用している個所をなくした - doSelectFolder() は doSelectFolderW() のラッパとした - doSelectFolderW() を common/ttlib_static_cpp.cpp へ移動 - 現在 doSelectFolderW() 内部には MAX_PATH の上限がある - 内部で使用している SHGetPathFromIDListW() の仕様 - SHGetPathFromIDListEx() への切り替えで上限はなくなる? Modified Paths: -------------- trunk/teraterm/common/ttlib.c trunk/teraterm/common/ttlib.h trunk/teraterm/common/ttlib_static.c trunk/teraterm/common/ttlib_static_cpp.cpp trunk/teraterm/layer_for_unicode/layer_for_unicode.cpp trunk/teraterm/teraterm/addsetting.cpp trunk/teraterm/ttpdlg/ttdlg.c trunk/teraterm/ttpmacro/ttl_gui.cpp trunk/ttssh2/ttxssh/ttxssh.c -------------- next part -------------- Modified: trunk/teraterm/common/ttlib.c =================================================================== --- trunk/teraterm/common/ttlib.c 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/common/ttlib.c 2021-09-13 15:20:06 UTC (rev 9420) @@ -910,59 +910,19 @@ return TRUE; } -// -// cf. http://homepage2.nifty.com/DSS/VCPP/API/SHBrowseForFolder.htm -// -static int CALLBACK setDefaultFolder(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) -{ - if(uMsg == BFFM_INITIALIZED) { - SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData); - } - return 0; -} - BOOL doSelectFolder(HWND hWnd, char *path, int pathlen, const char *def, const char *msg) { - BROWSEINFOA bi; - LPITEMIDLIST pidlRoot; // \x83u\x83\x89\x83E\x83Y\x82̃\x8B\x81[\x83gPIDL - LPITEMIDLIST pidlBrowse; // \x83\x86\x81[\x83U\x81[\x82\xAA\x91I\x91\xF0\x82\xB5\x82\xBDPIDL - char buf[MAX_PATH]; - BOOL ret = FALSE; - - // \x83_\x83C\x83A\x83\x8D\x83O\x95\\x8E\xA6\x8E\x9E\x82̃\x8B\x81[\x83g\x83t\x83H\x83\x8B\x83_\x82\xCCPIDL\x82\xF0\x8E擾 - // \x81\xA6\x88ȉ\xBA\x82̓f\x83X\x83N\x83g\x83b\x83v\x82\xF0\x83\x8B\x81[\x83g\x82Ƃ\xB5\x82Ă\xA2\x82\xE9\x81B\x83f\x83X\x83N\x83g\x83b\x83v\x82\xF0\x83\x8B\x81[\x83g\x82Ƃ\xB7\x82\xE9 - // \x8Fꍇ\x82́A\x92P\x82\xC9 bi.pidlRoot \x82ɂO\x82\xF0\x90ݒ肷\x82邾\x82\xAF\x82ł\xE0\x82悢\x81B\x82\xBB\x82̑\xBC\x82̓\xC1 - // \x8E\xEA\x83t\x83H\x83\x8B\x83_\x82\xF0\x83\x8B\x81[\x83g\x82Ƃ\xB7\x82鎖\x82\xE0\x82ł\xAB\x82\xE9\x81B\x8Fڍׂ\xCDSHGetSpecialFolderLoca - // tion\x82̃w\x83\x8B\x83v\x82\xF0\x8EQ\x8FƂ̎\x96\x81B - if (!SUCCEEDED(SHGetSpecialFolderLocation(hWnd, CSIDL_DESKTOP, &pidlRoot))) { - return FALSE; + wchar_t *defW = ToWcharA(def); + wchar_t *msgW = ToWcharA(msg); + wchar_t *pathW; + BOOL r = doSelectFolderW(hWnd, defW, msgW, &pathW); + if (r == TRUE) { + WideCharToACP_t(pathW, path, pathlen); + free(pathW); } - - // BROWSEINFO\x8D\\x91\xA2\x91̂̏\x89\x8A\xFA\x92l\x90ݒ\xE8 - // \x81\xA6BROWSEINFO\x8D\\x91\xA2\x91̂̊e\x83\x81\x83\x93\x83o\x82̏ڍא\xE0\x96\xBE\x82\xE0\x83w\x83\x8B\x83v\x82\xF0\x8EQ\x8F\xC6 - bi.hwndOwner = hWnd; - bi.pidlRoot = pidlRoot; - bi.pszDisplayName = buf; - bi.lpszTitle = msg; - bi.ulFlags = 0; - bi.lpfn = setDefaultFolder; - bi.lParam = (LPARAM)def; - // \x83t\x83H\x83\x8B\x83_\x91I\x91\xF0\x83_\x83C\x83A\x83\x8D\x83O\x82̕\\x8E\xA6 - pidlBrowse = SHBrowseForFolderA(&bi); - if (pidlBrowse != NULL) { - // PIDL\x8C`\x8E\xAE\x82̖߂\xE8\x92l\x82̃t\x83@\x83C\x83\x8B\x83V\x83X\x83e\x83\x80\x82̃p\x83X\x82ɕϊ\xB7 - if (SHGetPathFromIDListA(pidlBrowse, buf)) { - // \x8E擾\x90\xAC\x8C\xF7 - strncpy_s(path, pathlen, buf, _TRUNCATE); - ret = TRUE; - } - // SHBrowseForFolder\x82̖߂\xE8\x92lPIDL\x82\xF0\x89\xF0\x95\xFA - CoTaskMemFree(pidlBrowse); - } - // \x83N\x83\x8A\x81[\x83\x93\x83A\x83b\x83v\x8F\x88\x97\x9D - CoTaskMemFree(pidlRoot); - - return ret; + free(msgW); + free(defW); + return r; } void OutputDebugPrintf(const char *fmt, ...) Modified: trunk/teraterm/common/ttlib.h =================================================================== --- trunk/teraterm/common/ttlib.h 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/common/ttlib.h 2021-09-13 15:20:06 UTC (rev 9420) @@ -94,7 +94,7 @@ void get_lang_msgW(const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile); int get_lang_font(const char *key, HWND dlg, PLOGFONT logfont, HFONT *font, const char *iniFile); DllExport BOOL doSelectFolder(HWND hWnd, char *path, int pathlen, const char *def, const char *msg); -BOOL doSelectFolderW(HWND hWnd, wchar_t *path, int pathlen, const wchar_t *def, const wchar_t *msg); +BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder); DllExport void OutputDebugPrintf(const char *fmt, ...); void OutputDebugPrintfW(const wchar_t *fmt, ...); void OutputDebugHexDump(const void *data, size_t len); Modified: trunk/teraterm/common/ttlib_static.c =================================================================== --- trunk/teraterm/common/ttlib_static.c 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/common/ttlib_static.c 2021-09-13 15:20:06 UTC (rev 9420) @@ -352,61 +352,4 @@ OutputDebugStringW(tmp); } -static int CALLBACK setDefaultFolder(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) -{ - if(uMsg == BFFM_INITIALIZED) { - if (IsWindowsNTKernel()) { - SendMessageW(hwnd, BFFM_SETSELECTIONW, (WPARAM)TRUE, lpData); - } else { - // NT\x8Cn\x82ł͂Ȃ\xA2\x82Ƃ\xAB\x81ALayer for unicode \x82\xAA\x8Eg\x97p\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x82Ǝv\x82\xED\x82\xEA\x82\xE9 - SendMessageA(hwnd, BFFM_SETSELECTIONA, (WPARAM)TRUE, lpData); - } - } - return 0; -} - -BOOL doSelectFolderW(HWND hWnd, wchar_t *path, int pathlen, const wchar_t *def, const wchar_t *msg) -{ - BROWSEINFOW bi; - LPITEMIDLIST pidlRoot; // \x83u\x83\x89\x83E\x83Y\x82̃\x8B\x81[\x83gPIDL - LPITEMIDLIST pidlBrowse; // \x83\x86\x81[\x83U\x81[\x82\xAA\x91I\x91\xF0\x82\xB5\x82\xBDPIDL - wchar_t buf[MAX_PATH]; - BOOL ret = FALSE; - - // \x83_\x83C\x83A\x83\x8D\x83O\x95\\x8E\xA6\x8E\x9E\x82̃\x8B\x81[\x83g\x83t\x83H\x83\x8B\x83_\x82\xCCPIDL\x82\xF0\x8E擾 - // \x81\xA6\x88ȉ\xBA\x82̓f\x83X\x83N\x83g\x83b\x83v\x82\xF0\x83\x8B\x81[\x83g\x82Ƃ\xB5\x82Ă\xA2\x82\xE9\x81B\x83f\x83X\x83N\x83g\x83b\x83v\x82\xF0\x83\x8B\x81[\x83g\x82Ƃ\xB7\x82\xE9 - // \x8Fꍇ\x82́A\x92P\x82\xC9 bi.pidlRoot \x82ɂO\x82\xF0\x90ݒ肷\x82邾\x82\xAF\x82ł\xE0\x82悢\x81B\x82\xBB\x82̑\xBC\x82̓\xC1 - // \x8E\xEA\x83t\x83H\x83\x8B\x83_\x82\xF0\x83\x8B\x81[\x83g\x82Ƃ\xB7\x82鎖\x82\xE0\x82ł\xAB\x82\xE9\x81B\x8Fڍׂ\xCDSHGetSpecialFolderLoca - // tion\x82̃w\x83\x8B\x83v\x82\xF0\x8EQ\x8FƂ̎\x96\x81B - if (!SUCCEEDED(SHGetSpecialFolderLocation(hWnd, CSIDL_DESKTOP, &pidlRoot))) { - return FALSE; - } - - // BROWSEINFO\x8D\\x91\xA2\x91̂̏\x89\x8A\xFA\x92l\x90ݒ\xE8 - // \x81\xA6BROWSEINFO\x8D\\x91\xA2\x91̂̊e\x83\x81\x83\x93\x83o\x82̏ڍא\xE0\x96\xBE\x82\xE0\x83w\x83\x8B\x83v\x82\xF0\x8EQ\x8F\xC6 - bi.hwndOwner = hWnd; - bi.pidlRoot = pidlRoot; - bi.pszDisplayName = buf; - bi.lpszTitle = msg; - bi.ulFlags = 0; - bi.lpfn = setDefaultFolder; - bi.lParam = (LPARAM)def; - // \x83t\x83H\x83\x8B\x83_\x91I\x91\xF0\x83_\x83C\x83A\x83\x8D\x83O\x82̕\\x8E\xA6 - pidlBrowse = SHBrowseForFolderW(&bi); - if (pidlBrowse != NULL) { - // PIDL\x8C`\x8E\xAE\x82̖߂\xE8\x92l\x82̃t\x83@\x83C\x83\x8B\x83V\x83X\x83e\x83\x80\x82̃p\x83X\x82ɕϊ\xB7 - if (SHGetPathFromIDListW(pidlBrowse, buf)) { - // \x8E擾\x90\xAC\x8C\xF7 - wcsncpy_s(path, pathlen, buf, _TRUNCATE); - ret = TRUE; - } - // SHBrowseForFolder\x82̖߂\xE8\x92lPIDL\x82\xF0\x89\xF0\x95\xFA - CoTaskMemFree(pidlBrowse); - } - // \x83N\x83\x8A\x81[\x83\x93\x83A\x83b\x83v\x8F\x88\x97\x9D - CoTaskMemFree(pidlRoot); - - return ret; -} - /* vim: set ts=4 sw=4 ff=dos : */ Modified: trunk/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- trunk/teraterm/common/ttlib_static_cpp.cpp 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/common/ttlib_static_cpp.cpp 2021-09-13 15:20:06 UTC (rev 9420) @@ -1069,3 +1069,62 @@ _SHGetKnownFolderPath(FOLDERID_Downloads, 0, NULL, &download); return download; } + +static int CALLBACK BrowseCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) +{ + switch(uMsg) { + case BFFM_INITIALIZED: { + // \x8F\x89\x8A\x{227B39E} + + const wchar_t *folder = (wchar_t *)lpData; + if (folder == NULL || folder[0] == 0) { + // \x91I\x91\xF0\x83t\x83H\x83\x8B\x83_\x82\xAA\x8Ew\x92肳\x82\xEA\x82Ă\xA2\x82Ȃ\xA2 + break; + } + // \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x8F\xF3\x91Ԃɂ\xB7\x82\xE9 + SendMessageW(hwnd, BFFM_SETSELECTIONW, (WPARAM)TRUE, (LPARAM)folder); + break; + } + default: + break; + } + return 0; +} + +/** + * \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x82\xB7\x82\xE9 + * SHBrowseForFolderW() \x82\xF0\x83R\x81[\x83\x8B\x82\xB7\x82\xE9 + * + * @param[in] def \x91I\x91\xF0\x83t\x83H\x83\x8B\x83_\x82̏\x89\x8A\xFA\x92l(\x93\xC1\x82Ɏw\x92肵\x82Ȃ\xA2\x82Ƃ\xAB\x82\xCD NULL or "") + * @param[out] **folder \x91I\x91\xF0\x82\xB5\x82\xBD\x83t\x83H\x83\x8B\x83_\x82̃t\x83\x8B\x83p\x83X(\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x8E\x9E\x82̓Z\x83b\x83g\x82\xB3\x82\xEA\x82Ȃ\xA2) + * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6(\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x8E\x9E\x82\xCDfree()\x95s\x97v) + * @retval TRUE \x91I\x91\xF0\x82\xB5\x82\xBD + * @retval FALSE \x83L\x83\x83\x83\x93\x83Z\x83\x8B\x82\xB5\x82\xBD + * + */ +BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder) +{ + wchar_t buf[MAX_PATH]; + BROWSEINFOW bi = {}; + bi.hwndOwner = hWnd; + bi.pidlRoot = 0; // 0 = from desktop + bi.pszDisplayName = buf; + bi.lpszTitle = msg; + bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE; + bi.lpfn = BrowseCallback; + bi.lParam = (LPARAM)def; + LPITEMIDLIST pidlBrowse = SHBrowseForFolderW(&bi); + if (pidlBrowse == NULL) { + *folder = NULL; + return FALSE; + } + + // PIDL\x8C`\x8E\xAE\x82̖߂\xE8\x92l\x82̃t\x83@\x83C\x83\x8B\x83V\x83X\x83e\x83\x80\x82̃p\x83X\x82ɕϊ\xB7 + // TODO SHGetPathFromIDListEx() \x82\xE8\x91ւ\xA6? + if (!SHGetPathFromIDListW(pidlBrowse, buf)) { + return FALSE; + } + *folder = _wcsdup(buf); + CoTaskMemFree(pidlBrowse); + return TRUE; +} Modified: trunk/teraterm/layer_for_unicode/layer_for_unicode.cpp =================================================================== --- trunk/teraterm/layer_for_unicode/layer_for_unicode.cpp 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/layer_for_unicode/layer_for_unicode.cpp 2021-09-13 15:20:06 UTC (rev 9420) @@ -171,7 +171,7 @@ return (int)lenW; } -static LRESULT SendMessageAFromW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +LRESULT WINAPI _SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { LRESULT retval; switch(Msg) { @@ -215,6 +215,17 @@ free(strW); return dest_len - 1 < lenW ? dest_len - 1 : lenW; } + case BFFM_SETSELECTIONW: { + if (wParam == TRUE) { + // \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x8F\xF3\x91Ԃɂ\xB7\x82\xE9 + char *folderA = ToCharW((wchar_t *)lParam); + retval = SendMessageA(hWnd, BFFM_SETSELECTIONA, wParam, (LPARAM)folderA); + free(folderA); + } + else { + retval = SendMessageA(hWnd, Msg, wParam, lParam); + } + } default: retval = SendMessageA(hWnd, Msg, wParam, lParam); break; @@ -222,15 +233,10 @@ return retval; } -LRESULT WINAPI _SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) -{ - return SendMessageAFromW(hWnd, Msg, wParam, lParam); -} - LRESULT WINAPI _SendDlgItemMessageW(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) { HWND hWnd = GetDlgItem(hDlg, nIDDlgItem); - return SendMessageAFromW(hWnd, Msg, wParam, lParam); + return _SendMessageW(hWnd, Msg, wParam, lParam); } HWND WINAPI _CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, @@ -477,7 +483,7 @@ LPITEMIDLIST WINAPI _SHBrowseForFolderW(LPBROWSEINFOW lpbi) { char display_name[MAX_PATH]; - BROWSEINFOA biA; + BROWSEINFOA biA = {}; biA.hwndOwner = lpbi->hwndOwner; biA.pidlRoot = lpbi->pidlRoot; biA.pszDisplayName = display_name; Modified: trunk/teraterm/teraterm/addsetting.cpp =================================================================== --- trunk/teraterm/teraterm/addsetting.cpp 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/teraterm/addsetting.cpp 2021-09-13 15:20:06 UTC (rev 9420) @@ -54,6 +54,7 @@ #include "coding_pp.h" #include "font_pp.h" #include "asprintf.h" +#include "win32helper.h" const mouse_cursor_t MouseCursor[] = { {"ARROW", IDC_ARROW}, @@ -1424,12 +1425,14 @@ // \x83\x8D\x83O\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82̑I\x91\xF0\x83_\x83C\x83A\x83\x8D\x83O { wchar_t *title = TTGetLangStrW("Tera Term", "FILEDLG_SELECT_LOGDIR_TITLE", L"Select log folder", ts.UILanguageFile); - wchar_t buf[MAX_PATH]; - wchar_t buf2[MAX_PATH]; - GetDlgItemTextW(IDC_DEFAULTPATH_EDITOR, buf, _countof(buf)); - if (doSelectFolderW(GetSafeHwnd(), buf2, _countof(buf2), buf, title)) { + wchar_t *buf; + hGetDlgItemTextW(m_hWnd, IDC_DEFAULTPATH_EDITOR, &buf); + wchar_t *buf2; + if (doSelectFolderW(GetSafeHwnd(), buf, title, &buf2)) { SetDlgItemTextW(IDC_DEFAULTPATH_EDITOR, buf2); + free(buf2); } + free(buf); free(title); } @@ -1662,16 +1665,18 @@ BOOL CCygwinPropPageDlg::OnCommand(WPARAM wParam, LPARAM lParam) { - wchar_t buf[MAX_PATH], buf2[MAX_PATH]; - switch (wParam) { case IDC_SELECT_FILE | (BN_CLICKED << 16): // Cygwin install \x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82̑I\x91\xF0\x83_\x83C\x83A\x83\x8D\x83O wchar_t *title = TTGetLangStrW("Tera Term", "DIRDLG_CYGTERM_DIR_TITLE", L"Select Cygwin directory", ts.UILanguageFile); - GetDlgItemTextW(IDC_CYGWIN_PATH, buf, _countof(buf)); - if (doSelectFolderW(GetSafeHwnd(), buf2, _countof(buf2), buf, title)) { - SetDlgItemTextW(IDC_CYGWIN_PATH, buf2); + wchar_t *buf; + hGetDlgItemTextW(m_hWnd, IDC_CYGWIN_PATH, &buf); + wchar_t *path; + if (doSelectFolderW(GetSafeHwnd(), buf, title, &path)) { + SetDlgItemTextW(IDC_CYGWIN_PATH, path); + free(path); } + free(buf); free(title); return TRUE; } Modified: trunk/teraterm/ttpdlg/ttdlg.c =================================================================== --- trunk/teraterm/ttpdlg/ttdlg.c 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/ttpdlg/ttdlg.c 2021-09-13 15:20:06 UTC (rev 9420) @@ -53,6 +53,7 @@ #include "codeconv.h" #include "helpid.h" #include "asprintf.h" +#include "win32helper.h" // Oniguruma: Regular expression library #define ONIG_EXTERN extern @@ -2081,7 +2082,6 @@ POINT D, B, S; int WX, WY, WW, WH, CW, DW, DH, BW, BH, SW, SH; char uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG]; - char buf[MAX_PATH], buf2[MAX_PATH]; switch (Message) { case WM_INITDIALOG: @@ -2197,18 +2197,23 @@ EndDialog(Dialog, 0); return TRUE; - case IDC_SELECT_DIR: - get_lang_msg("DLG_SELECT_DIR_TITLE", uimsg, sizeof(uimsg), - "Select new directory", UILanguageFile); + case IDC_SELECT_DIR: { + wchar_t uimsgW[MAX_UIMSG]; + wchar_t *buf, *buf2; + get_lang_msgW("DLG_SELECT_DIR_TITLE", uimsgW, _countof(uimsgW), + L"Select new directory", UILanguageFile); { - char FileDirExpanded[MAX_PATH]; - GetDlgItemText(Dialog, IDC_DIRNEW, buf, sizeof(buf)); - ExpandEnvironmentStrings(buf, FileDirExpanded, sizeof(FileDirExpanded)); - if (doSelectFolder(Dialog, buf2, sizeof(buf2), FileDirExpanded, uimsg)) { - SetDlgItemText(Dialog, IDC_DIRNEW, buf2); + wchar_t FileDirExpanded[MAX_PATH]; + hGetDlgItemTextW(Dialog, IDC_DIRNEW, &buf); + ExpandEnvironmentStringsW(buf, FileDirExpanded, _countof(FileDirExpanded)); + if (doSelectFolderW(Dialog, FileDirExpanded, uimsgW, &buf2)) { + SetDlgItemTextW(Dialog, IDC_DIRNEW, buf2); + free(buf2); } + free(buf); } return TRUE; + } case IDC_DIRHELP: PostMessage(GetParent(Dialog),WM_USER_DLGHELP2,HlpFileChangeDir,0); Modified: trunk/teraterm/ttpmacro/ttl_gui.cpp =================================================================== --- trunk/teraterm/ttpmacro/ttl_gui.cpp 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/teraterm/ttpmacro/ttl_gui.cpp 2021-09-13 15:20:06 UTC (rev 9420) @@ -317,11 +317,12 @@ if (CheckVar("inputstr", &ValType, &VarId) && (ValType == TypString)) { BringupWindow(GetHWND()); - wchar_t buf[MAX_PATH]; - if (doSelectFolderW(GetHWND(), buf, _countof(buf), wc::fromUtf8(InitDir), wc::fromUtf8(Title))) { + wchar_t *buf; + if (doSelectFolderW(GetHWND(), wc::fromUtf8(InitDir), wc::fromUtf8(Title), &buf)) { const char *bufU8 = ToU8W(buf); SetInputStr((PCHAR)bufU8); free((void *)bufU8); + free(buf); ret = 1; } else { Modified: trunk/ttssh2/ttxssh/ttxssh.c =================================================================== --- trunk/ttssh2/ttxssh/ttxssh.c 2021-09-13 15:19:56 UTC (rev 9419) +++ trunk/ttssh2/ttxssh/ttxssh.c 2021-09-13 15:20:06 UTC (rev 9420) @@ -3306,13 +3306,14 @@ return TRUE; case IDC_RECVDIR_SELECT | (BN_CLICKED << 16): { - char buf[MAX_PATH], buf2[MAX_PATH]; - hWnd = GetDlgItem(dlg, IDC_RECVFILE_TO); - SendMessage(hWnd, WM_GETTEXT , sizeof(buf), (LPARAM)buf); - if (doSelectFolder(dlg, buf2, sizeof(buf2), buf, "Choose destination directory")) { - strncpy_s(recvdir, sizeof(recvdir), buf2, _TRUNCATE); - SendMessage(GetDlgItem(dlg, IDC_RECVFILE_TO), WM_SETTEXT, 0, (LPARAM)recvdir); + wchar_t *buf, *buf2; + hGetDlgItemTextW(dlg, IDC_RECVFILE_TO, &buf); + if (doSelectFolderW(dlg, buf, L"Choose destination directory", &buf2)) { + WideCharToACP_t(buf2, recvdir, sizeof(recvdir)); + SetDlgItemTextA(dlg, IDC_RECVFILE_TO, recvdir); + free(buf2); } + free(buf); } return TRUE; }