Imports Microsoft.VisualBasic.CompilerServices
Public Class CtrlIni
Public Property iniFilePath As String
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
Public Function GetINI(ByVal Section As String, ByVal AppName As String, Optional ByVal lpDefault As String = "") As String
Dim Str As String = ""
Str = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), iniFilePath)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
Public Function SetINI(ByVal Section As String, ByVal AppName As String, ByVal lpString As String) As Boolean
Try
WritePrivateProfileString(Section, AppName, lpString, iniFilePath)
Catch exception1 As Exception
Return False
End Try
Return True
End Function
End Class