Hello. The problem is as follows. Wrote applications one of the functions of which is a recursive directory traversal. When this application is launched on another computer with another language installed, it crashes with the message PROGRAM CRASH. Through a long search, I found that the problem lies in the names of files and folders containing Chinese characters. When the program reaches them, it crashes with the above error. How to add support for different languages to a Visual Studio project? Tell me please. Already day I suffer with this.
WIN32_FIND_DATAW ffd; TCHAR szDir[MAX_PATH]; size_t length_of_arg; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD dwError = 0; StringCchLength(dir, MAX_PATH, &length_of_arg); StringCchCopy(szDir, MAX_PATH, dir); StringCchCat(szDir, MAX_PATH, TEXT("\\*")); hFind = FindFirstFile(szDir, &ffd); if (INVALID_HANDLE_VALUE == hFind) { return 0; } do { try { if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (!(std::wstring(L".") == std::wstring(ffd.cFileName)) && !(std::wstring(L"..") == std::wstring(ffd.cFileName)))) { try { TCHAR directory[MAX_PATH]; StringCchCopy(directory, MAX_PATH, dir); StringCchCat(directory, MAX_PATH, TEXT("\\")); StringCchCat(directory, MAX_PATH, ffd.cFileName); //wprintf(L"%s: %s\n", L"Folder", directory); get_paths_arguments((STRSAFE_LPWSTR)directory, ctls, len); } catch (exception &ex) { std::cout << "EXCEPTION ON GET DIR NAME"; } } } else { if (ffd.cFileName != NULL) { TCHAR directory[MAX_PATH]; StringCchCopy(directory, MAX_PATH, dir); StringCchCat(directory, MAX_PATH, TEXT("\\")); StringCchCat(directory, MAX_PATH, ffd.cFileName); //wprintf(L"%s: %s\n", L"File", directory); ctls->catls[*len].name = (STRSAFE_LPWSTR)directory; *len = *len + 1; ctls->length = *len; //cout << hFind << endl; if (*len == (ctls->size - 1)) { std::cout << "CRITICAL SIZE OF PATHS STRUCTURE" << std::endl; FindClose(hFind); return 0; } } } } catch (char * str) { cout << "EXCEPTION ON GET_PATHS_ARGUMENTS: " << *str << endl; return 0; } } while (FindNextFile(hFind, &ffd)); FindClose(hFind); return 0;