You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Basic
|
|
|
|
|
{
|
|
|
|
|
public class Win32Tool
|
|
|
|
|
{
|
|
|
|
|
#region 定义外部函数
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ini文件写入
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="section">写入ini文件的某个小节名称(不区分大小写)</param>
|
|
|
|
|
/// <param name="key">上面section下某个项的键名(不区分大小写)</param>
|
|
|
|
|
/// <param name="val">上面key对应的value</param>
|
|
|
|
|
/// <param name="filePath">ini的文件名,包括其路径(example: "c:\config.ini")。如果没有指定路径,仅有文件名,系统会自动在windows目录中查找是否有对应的ini文件,如果没有则会自动在当前应用程序运行的根目录下创建ini文件</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[DllImport("kernel32")]
|
|
|
|
|
public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ini文件读取
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="section">某个小节名(不区分大小写),如果为空,则将在retVal内装载这个ini文件的所有小节列表</param>
|
|
|
|
|
/// <param name="key">欲获取信息的某个键名(不区分大小写),如果为空,则将在retVal内装载指定小节下的所有键列表</param>
|
|
|
|
|
/// <param name="def">当指定信息,未找到时,则返回def,可以为空</param>
|
|
|
|
|
/// <param name="retVal">一个字串缓冲区,所要获取的字符串将被保存在其中,其缓冲区大小至少为size</param>
|
|
|
|
|
/// <param name="size">retVal的缓冲区大小(最大字符数量)</param>
|
|
|
|
|
/// <param name="filePath">指定的ini文件路径,如果没有路径,则在windows目录下查找,如果还是没有则在应用程序目录下查找,再没有,就只能返回def了</param>
|
|
|
|
|
/// <returns>返回所取信息字符串的字节长度</returns>
|
|
|
|
|
[DllImport("kernel32")]
|
|
|
|
|
public static extern long GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|