读写ini文件的接口
Private Declare Function GetPrivateProfileString Lib "Kernel32" _
Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal Key As Any, _
ByVal Value As String, _
ByVal ReturnedString As String, _
ByVal Size As Long, _
ByVal FilePath As String) As Long
Private Declare Function WritePrivateProfileString Lib "Kernel32" _
Alias "WritePrivateProfileStringA" _
(ByVal Section As String, _
ByVal Key As Any, _
ByVal Value As Any, _
ByVal FilePath As String) As Long
进一步封装接口
Public Function ReadFromIni(ByVal Section As String, ByVal Key As String, ByVal Value As String, ByVal FilePath As String) As String
Dim str As String
str = Space(256)
Dim ln As Long
ln = GetPrivateProfileString(Section, Key, Value, str, 255, FilePath)
If ln > 0 Then
str = Trim(str)
ReadFromIni = Mid(str, 1, Len(str) - 1)
Else
ReadFromIni = Value
End If
End Function
Public Function WriteToIni(ByVal Section As String, ByVal Key As String, ByVal Value As String, ByVal FilePath As String) As String
Dim l As Long
l = WritePrivateProfileString(Section, Key, Value, FilePath)
End Function