Attribute VB_Name = "RWini"
'*************************************************************************
'**模 块 名：RWini
'**说    明：对INI文件进行读写操作
'**创 建 人：马大哈
'**日    期：2003年10月26日
'**修 改 人：
'**日    期：
'**描    述：
'**版    本：
'*************************************************************************
Option Explicit
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public IniFileName As String

Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefString As String) As String
Dim ResultString As String * 144, Temp As Integer
Dim S As String, I As Integer

Temp% = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 144, IniFileName)

If Temp% > 0 Then
    S = ""
    For I = 1 To 144
        If Asc(Mid$(ResultString, I, 1)) = 0 Then
            Exit For
        Else
            S = S & Mid$(ResultString, I, 1)
        End If
    Next
Else
    Temp% = WritePrivateProfileString(SectionName, KeyWord, DefString, IniFileName)
    S = DefString
End If

GetIniS = S

End Function

Function GetIniN(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefValue As Integer) As Integer
Dim D As Long, S As String

D = DefValue
GetIniN = GetPrivateProfileInt(SectionName, KeyWord, DefValue, IniFileName)

If D <> DefValue Then
    S = "" & D
    D = WritePrivateProfileString(SectionName, KeyWord, S, IniFileName)
End If

End Function

Sub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValStr As String)
Dim Res%

Res% = WritePrivateProfileString(SectionName, KeyWord, ValStr, IniFileName)

End Sub

Sub SetIniN(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValInt As Integer)
Dim Res%, S$

S$ = Str$(ValInt)
Res% = WritePrivateProfileString(SectionName, KeyWord, S$, IniFileName)

End Sub

