private static string iNIGetStringValue(string iniFile, string section, string key, string defaultValue) { string value = defaultValue; const int SIZE = 1024 * 10; if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("必须指定键名称(key)", "key"); } StringBuilder sb = new StringBuilder(SIZE); uint bytesReturned = INIOperationClass.GetPrivateProfileString(section, key, defaultValue, sb, SIZE, iniFile); if (bytesReturned != 0) { value = sb.ToString(); } sb = null; return(value); }
private static string[] iNIGetAllItemKeys(string iniFile, string section) { string[] value = new string[0]; const int SIZE = 1024 * 10; if (string.IsNullOrEmpty(section)) { throw new ArgumentException("必须指定节点名称", "section"); } char[] chars = new char[SIZE]; uint bytesReturned = INIOperationClass.GetPrivateProfileString(section, null, null, chars, SIZE, iniFile); if (bytesReturned != 0) { value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } chars = null; return(value); }