cINIFile.cls
资源名称:IE_VB.rar [点击查看]
上传用户:davilee3
上传日期:2015-04-22
资源大小:986k
文件大小:5k
源码类别:
浏览器
开发平台:
Visual Basic
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- Persistable = 0 'NotPersistable
- DataBindingBehavior = 0 'vbNone
- DataSourceBehavior = 0 'vbNone
- MTSTransactionMode = 0 'NotAnMTSObject
- END
- Attribute VB_Name = "cINIFile"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- '---------------------------------------------------------------------------------------
- ' Module : cINIFile
- ' DateTime : 2005-3-19 20:17
- ' Author : Lingll
- ' Purpose :
- '---------------------------------------------------------------------------------------
- '2005-3-19 添加函数ReadSection,ReadSection2,ReadInt
- '8/5/2005 :strconv 增加使用了 LocaleID参数
- Option Explicit
- '确保strconv能正确转换
- Private Const LocaleID_SC As Long = 2052& '简中
- Private Const LocaleID_CurUse As Long = LocaleID_SC
- Private Declare Function GetPrivateProfileSection Lib "kernel32.dll" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As Long, ByVal nSize As Long, ByVal lpFileName As String) As Long
- Private Declare Function GetPrivateProfileInt Lib "kernel32.dll" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
- Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As Long, ByVal nSize As Long, ByVal lpFileName As String) As Long
- Private 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
- Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
- Public IniFile As String
- Public bffSize As Long
- Public Function ReadInt(SectionName$, KeyName$, Optional nDefault& = 0) As Long
- ReadInt = GetPrivateProfileInt(SectionName, KeyName, nDefault, IniFile)
- End Function
- Public Function ReadSection(SectionName$) As String
- Dim tBff() As Byte
- Dim tLen As Long
- tLen = FileLen(IniFile)
- If tLen > 0 Then
- ReDim tBff(0 To tLen - 1)
- tLen = GetPrivateProfileSection(SectionName, VarPtr(tBff(0)), tLen, IniFile)
- If tLen > 1 Then
- ReDim Preserve tBff(0 To tLen - 2)
- ReadSection = Replace$(StrConv(tBff, vbUnicode, LocaleID_CurUse), vbNullChar, vbNewLine)
- End If
- End If
- End Function
- Public Function ReadSection2(SectionName$, ptArr&, nSize&) As Long
- ReadSection2 = GetPrivateProfileSection(SectionName, ptArr, nSize, IniFile)
- End Function
- Public Function ReadKey(SectionName As String, _
- KeyName As String, Optional DefaultVal As String = vbNullString, _
- Optional IniName As String = vbNullString) As String
- Dim tBff() As Byte
- ' Dim tmpPos As Integer
- Dim tBffLen&, tIniFile$
- If LenB(IniName) <> 0 Then
- tIniFile = IniName
- Else
- tIniFile = IniFile
- End If
- ReDim tBff(0 To bffSize - 1)
- tBffLen = GetPrivateProfileString(SectionName, KeyName, _
- DefaultVal, VarPtr(tBff(0)), bffSize, tIniFile)
- If tBffLen > 0 Then
- ReDim Preserve tBff(0 To tBffLen - 1)
- ReadKey = StrConv(tBff, vbUnicode, LocaleID_CurUse)
- Else
- ReadKey = vbNullString '""
- End If
- End Function
- Public Function WriteKey(SectionName As String, KeyName As String, _
- nKey As String, Optional IniName As String = vbNullString) As Boolean
- Dim rtn&
- Dim tIniFile$
- If LenB(IniName) <> 0 Then
- tIniFile = IniName
- Else
- tIniFile = IniFile
- End If
- rtn = WritePrivateProfileString(SectionName, _
- KeyName, nKey, tIniFile)
- If rtn <> 0 Then
- WriteKey = True
- Else
- WriteKey = False
- End If
- End Function
- Public Function DeleteKey(SectionName As String, KeyName As String, _
- Optional IniName As String = vbNullString) As Boolean
- Dim rtn&
- Dim tIniFile$
- If LenB(IniName) <> 0 Then
- tIniFile = IniName
- Else
- tIniFile = IniFile
- End If
- rtn = WritePrivateProfileString(SectionName, _
- KeyName, 0&, tIniFile)
- If rtn <> 0 Then
- DeleteKey = True
- Else
- DeleteKey = False
- End If
- End Function
- Public Function DeleteSection(SectionName As String, _
- Optional IniName As String = vbNullString) As Boolean
- Dim rtn&
- Dim tIniFile$
- If LenB(IniName) <> 0 Then
- tIniFile = IniName
- Else
- tIniFile = IniFile
- End If
- rtn = WritePrivateProfileString(SectionName, _
- 0&, 0&, tIniFile)
- If rtn <> 0 Then
- DeleteSection = True
- Else
- DeleteSection = False
- End If
- End Function
- Private Sub Class_Initialize()
- IniFile = vbNullString '""
- bffSize = &H400& ' 256
- End Sub