如果在C#中要用到INI配置文档那么就应该要考虑Unicode 的问题。
下面介绍一下在C#中使用Unicode INI档的方法。
首先,需要创建一个Unicode的文件,可以使用如下方法创建:
File.WriteAllText(FilePath, string.Empty, System.Text.Encoding.Unicode);
然后,读写文件调用系统的API函数,声明如下:
[System.Runtime.InteropServices.DllImport("kernel32", CharSet = CharSet.Unicode)]
public static extern long WritePrivateProfileString(string section, string KeyName, string Val, string FilePath);
[System.Runtime.InteropServices.DllImport("kernel32", CharSet = CharSet.Unicode)]
public static extern long GetPrivateProfileString(string section, string lpKeyName, string lpDefault, System.Text.StringBuilder lpReturnedString, int nSize, string FilePath);
[System.Runtime.InteropServices.DllImport("kernel32", CharSet = CharSet.Unicode)]
public static extern int GetPrivateProfileInt(string section, string lpKeyName, int nDefault, string FilePath);