2

I have a folder name in Japanese. CFileDialog getpathNameis returning some question marks when the folder is selected. Is there some way to solve it?

dda
  • 6,030
  • 2
  • 25
  • 34
sherin_
  • 352
  • 4
  • 15
  • 2
    Code snippet? is your app built with Unicode support enabled? – Roman R. Nov 09 '11 at 12:52
  • This is Visual-c++ (or something other?) related question, not general C++. Being more specific with tags helps the person who is capable of answering this question see it, helps other community members find the question and also increases your odds of getting the answer. It's a win-win-win ;] – friendzis Nov 09 '11 at 13:53
  • How do you know that `GetPathName` isn't returning the Japanese characters? Is it possible that the problem is in the code that displays the results and not in `GetPathName` itself? – Mark Ransom Nov 09 '11 at 17:19
  • @Roman no it is not built with Unicode Support enabled – sherin_ Nov 10 '11 at 03:35
  • @Mark When i stepped through the code, the cstring returned by GetPathName is showing some "?????" in place of japanese text – sherin_ Nov 10 '11 at 03:38
  • @friendzis Thanks for your comment. I will definitely note it in future questions – sherin_ Nov 10 '11 at 03:38
  • It's possible that the debugger is using a font that doesn't include Japanese. To be sure you should do a binary dump of the data. – Mark Ransom Nov 10 '11 at 03:56
  • THis is my code CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "JPEG Files (*.jpeg, *.jpg)|*.jpeg; *.jpg||", NULL ); if (dlg.DoModal() == IDOK) { SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); FileName = dlg.GetPathName(); Standard_CString aFileName = (Standard_CString)(LPCTSTRFileName; }. – sherin_ Nov 10 '11 at 04:47

1 Answers1

2

If your app is build with MBCS support rather than Unicode support, the japanese path will be handled correctly only if your "Language for non-Unicode programs" (aka system locale) is set to Japanese, which is the case for your Japanese users but might not be the case for you if you are not Japanese.

If your system locale is not Japanese, the path is translated to your codepage before it is returned by GetPathName(). It will either contain replacement (?) chars or garbage. Most likely a mix of both.

Here are a few possibilities available:

  1. Don't do anything. Your app should work fine for Japanese most users. Or not...

  2. Test your app under a Japanese codepage. To do so, either temporarily change your Language for non-Unicode programs (requires a reboot) or (much easier) test your app under AppLocale. (Note: Yes, it runs fine under Windows 7. This article may help if you have problems).

  3. Switch it to Unicode. According to the size of your codebase, this can be a very tedious task mostly depending on inputs and outputs and whether you use _T("blah") string literals in your code. Of course, there are more aspects to it but these ones are the most important. BTW, all new projects should be done with Unicode support in mind.

  4. Handle this path problem specifically. Since we're speaking of a file dialog, the whole dialog should be opened as Unicode. Which means you'll probably have to explicitely call the Unicode version of the underlying Win32 API rather than simply CFileDialog. It's not so complicated but the risk is that you are only solving the first problem in a row. After you have your Japanese path correctly, you'll have to deal with Japanese text input by user,... So I don't think this solution is a good one.

Solution #2 is certainly the quickest way to identify small issues. Solution #3 is for sure the best one on the long run. But make sure you actually need it because it may be tedious for existing apps.

Serge Wautier
  • 21,494
  • 13
  • 69
  • 110