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.

39 lines
2.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
}
}