Выношу на общее обсуждение класс для работы с файлами конфигурации. Приветствуются все критические замечания.
Исключение: Переходи на XML или используй My.Settings
Public Class INI
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal iniSection As String, ByVal iniKey As String, ByVal iniDefault As String, ByVal iniValue As String, ByVal iniBuffer As Integer, ByVal iniFilename As String) As Integer
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal iniSection As String, ByVal iniKey As String, ByVal iniValue As String, ByVal iniFilename As String) As Integer
Shared Function Read(ByVal iniSection As String, ByVal iniKey As String, ByVal iniDefault As String) As String
Dim iniBuffer As String = Space(255)
Dim iniLength As Integer = GetPrivateProfileString(iniSection, iniKey, iniDefault, iniBuffer, 255, Application.StartupPath + "SM+Settings.ini")
Return iniBuffer.Substring(0, iniLength)
End Function
Shared Sub Wright(ByVal iniSection As String, ByVal iniKey As String, ByVal iniValue As String)
WritePrivateProfileString(iniSection, iniKey, iniValue, Application.StartupPath + "SM+Settings.ini")
End Sub
Shared Sub DeleteValue(ByVal iniSection As String, ByVal iniKey As String)
WritePrivateProfileString(iniSection, iniKey, Nothing, Application.StartupPath + "SM+Settings.ini")
End Sub
Shared Sub DeleteSection(ByVal iniSection As String)
WritePrivateProfileString(iniSection, Nothing, Nothing, Application.StartupPath + "SM+Settings.ini")
End Sub
End Class