如果路径包含特殊字符,则 GetPrivateProfileString 不起作用
GetPrivateProfileString doesn't work if path contains special chars
我使用以下代码在 c# framework.net 2.0 中创建了一个 dll:
/// <summary>
/// Read Data Value From the Ini File
/// </summary>
/// <PARAM name="Section"></PARAM>
/// <PARAM name="Key"></PARAM>
/// <PARAM name="Path"></PARAM>
/// <returns></returns>
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
函数声明如下:
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
如果我创建一个调用此代码的 winform 项目,那么如果 ini 文件位于文档文件夹中并且用户有一个特殊的字符,如 ç
或 Д
。
这个 dll 我需要在 unity3d 中使用,并且工作正常但是如果文件夹包含上面的特殊字符 (示例) 它不起作用并且 return空字符串..
有什么想法吗?
使用CharSet=CharSet.Unicode
:
[DllImport("kernel32", CharSet=CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
我使用以下代码在 c# framework.net 2.0 中创建了一个 dll:
/// <summary>
/// Read Data Value From the Ini File
/// </summary>
/// <PARAM name="Section"></PARAM>
/// <PARAM name="Key"></PARAM>
/// <PARAM name="Path"></PARAM>
/// <returns></returns>
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
函数声明如下:
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
如果我创建一个调用此代码的 winform 项目,那么如果 ini 文件位于文档文件夹中并且用户有一个特殊的字符,如 ç
或 Д
。
这个 dll 我需要在 unity3d 中使用,并且工作正常但是如果文件夹包含上面的特殊字符 (示例) 它不起作用并且 return空字符串..
有什么想法吗?
使用CharSet=CharSet.Unicode
:
[DllImport("kernel32", CharSet=CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);