/// <summary> /// Gets the names of all keys under a specific section in the ini file. /// </summary> /// <param name="sectionName"> /// The name of the section to read key names from. /// </param> /// <returns>An array of key names.</returns> /// <remarks> /// The total length of all key names in the section must be /// less than 32KB in length. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="sectionName"/> is a null reference (Nothing in VB) /// </exception> public string[] GetKeyNames(string argSectionName) { int len; string[] retval; if (string.IsNullOrEmpty(argSectionName)) { return(null); } //Allocate a buffer for the returned section names. IntPtr ptr = Marshal.AllocCoTaskMem(IniHandler.MaxSectionSize); try { //Get the section names into the buffer. len = IniAPI.GetPrivateProfileString(argSectionName, null, null, ptr, IniHandler.MaxSectionSize, m_path); retval = ConvertNullSeperatedStringToStringArray(ptr, len); } finally { //Free the buffer Marshal.FreeCoTaskMem(ptr); } return(retval); }
/// <summary> /// Gets the value of a setting in an ini file as a <see cref="T:System.String"/>. /// </summary> /// <param name="argSectionName">The name of the section to read from.</param> /// <param name="argKeyName">The name of the key in section to read.</param> /// <param name="argDefaultValue">The default value to return if the key /// cannot be found.</param> /// <returns>The value of the key, if found. Otherwise, returns /// <paramref name="argDefaultValue"/></returns> /// <remarks> /// The retreived value must be less than 32KB in length. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="argSectionName"/> or <paramref name="argKeyName"/> are /// a null reference (Nothing in VB) /// </exception> public string GetString(string argSectionName, string argKeyName, string argDefaultValue = null) { if (string.IsNullOrEmpty(argSectionName) || string.IsNullOrEmpty(argKeyName)) { return(null); } StringBuilder retval = new StringBuilder(IniHandler.MaxSectionSize); IniAPI.GetPrivateProfileString(argSectionName, argKeyName, argDefaultValue, retval, IniHandler.MaxSectionSize, m_path); return(retval.ToString()); }