LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

INI (inifile) using utf-8 and chinese font, inside the ini file = ???

I'm using CVI 2020 on Win11. Now I want to save chinese strings into my ini file with Ini_PutString(). Inside the running program, the chinese font is showing fine, but after calling the function Ini_WriteToFile(), the chinese font inside the ini file is = ?. Is utf-8 not supported by the INI Library?

0 Kudos
Message 1 of 3
(50 Views)

Hello,

you’ve run into a limitation of CVI’s INI library. The functions Ini_PutString() and Ini_WriteToFile() in CVI 2020 store strings in ANSI encoding, not UTF-8. This is why non-ASCII characters like Chinese appear as ? in the file. Inside your running program, CVI uses Unicode internally for strings, so the Chinese characters display correctly in the GUI. However, when writing to the INI, the library converts the Unicode string to ANSI, causing any characters outside the current code page to be lost. To handle Chinese characters, you’ll need to bypass the CVI INI functions and write the INI file manually in UTF-8 or UTF-16, for example by opening the file in binary mode, optionally writing a UTF-8 BOM, and writing your strings in UTF-8 encoding.      e-zpassma

Message 2 of 3
(20 Views)

Thanks for your answer. Its funny, that the function name in inifile.c is "Ini_WriteToFileUtf8(IniText theIniText, const char pathName[])", very confusing 😄

 

UPDATE:

Solution: Ini_SetEncoding(g_myInifile, IniFileEncoding_UTF8BOM);

0 Kudos
Message 3 of 3
(11 Views)