zoukankan      html  css  js  c++  java
  • INI文件配置乱码——C#

    在声明时加上参数CharSet = CharSet.Unicode

    [DllImport("kernel32", CharSet = CharSet.Unicode)]

    CharSet: 指示如何向方法封送字符串参数,并控制名称重整。

    最后,附上读写ini文件,解决出现乱码的代码

    [DllImport("kernel32", CharSet = CharSet.Unicode)]
    private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
    [DllImport("kernel32", CharSet = CharSet.Unicode)]
    private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
            
    /// <summary>
    ///读取ini文件数据
    /// </summary>
    /// <param name="Section"></param>
    /// <param name="Key">键名</param>
    /// <param name="def">默认值</param>
    /// <param name="filePath">文件路径</param>
    /// <returns>读出内容</returns>
    public static string ReadValueFromIniFile(string Section, string Key, string def, string filePath)
    {
        StringBuilder temp = new StringBuilder(4096);
        int i = GetPrivateProfileString(Section, Key, def, temp, 4096, filePath);
        return temp.ToString();
    }
     
    /// <summary>
    /// 写入数据到ini文件
    /// </summary>
    /// <param name="Section"></param>
    /// <param name="Key">键名</param>
    /// <param name="Value">键值</param>
    /// <param name="filePath">文件路径</param>
    public static void WriteValueFromIniFile(string Section, string Key, string Value, string filePath)
    {
        WritePrivateProfileString(Section, Key, Value, filePath);
    }
  • 相关阅读:
    曲线与直线相切
    两函数切线
    导数+放缩
    选取拟合函数
    二分法求零点次数
    奇函数+方程的根与零点
    对数函数绝对值交点问题
    判断函数相等+判断反函数+判断周期函数
    已知分段函数零点个数求范围
    2020-05-03 助教一周小结(第十二周)
  • 原文地址:https://www.cnblogs.com/eve612/p/14234181.html
Copyright © 2011-2022 走看看