2

Using WritePrivateProfileString and GetPrivateProfileString results in ??? instead of the real characters.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

4 Answers4

9

GetPrivateProfileString() and WritePrivateProfileString() will work with Unicode, sort of.

If the ini file is UTF-16LE encoded, i.e. it has a UTF-16 BOM, then the functions will work in Unicode. However if the functions have to create the file they will create an ANSI file and only work in ANSI.

So to use the functions with Unicode, create your ini file before you first use it and write a UTF-16LE Byte Order Mark to it. Then carry on as normal.

Note that the functions do not work at all with UTF-8.

See Michael Kaplan's blog for more detail than you ever wanted to know about this.

Community
  • 1
  • 1
2

The WritePrivateProfileStringW function will write the INI file in legacy system encoding (e.g. Shift-JIS on a Japanese system) because it is a legacy support function. If you want to have a fully Unicode-enabled INI file, you will need to use an external library.

Try SimpleIni http://code.jellycan.com/simpleini/

It is C++, single header file, template library with an MIT licence (i.e. commercial use is OK). Include it into your source file and use it. It is cross-platform, supports UTF-8 and legacy encoded files, and can read and write the INI file largely preserving comments and structure, etc. Easiest to check out the page.

It's been around for a while and is appears to be used by quite a number of people. I wrote it and continue to support it.

brofield
  • 2,226
  • 1
  • 22
  • 25
1

According to the WritePrivateProfileString documentation, there is a Unicode version: WritePrivateProfileStringW. Use that, and you should be able to use Unicode characters.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
0

It might just be a problem with how you are displaying or handling the strings. For example, the normal console window can't display japanese strings with printf.

Can you post some of your code?

moogs
  • 8,122
  • 8
  • 44
  • 60