+ -
当前位置:首页 → 问答吧 → 关于读写INI文件的问题!

关于读写INI文件的问题!

时间:2011-12-21

来源:互联网

这个代码在读写ini文件时有字数限制.
怎么把它改成无限制的???
先上一段读写INI文件的代码.
VB code

'声明API函数
Private 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
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 iniFile As String
Private iniSec As String
Private iniKey As String

'-------------------------------------
Public Property Let FileName(strfile As String)
     If Right(strfile, 4) <> ".ini" Then
         strfile = strfile & ".ini"
     End If
     iniFile = strfile
End Property

Public Property Get FileName() As String
    FileName = iniFile
End Property

Public Property Let Section(strSection As String)
    iniSec = strSection
End Property
Public Property Get Section() As String
    Section = iniSec
End Property

Public Property Let Key(strKey As String)
    iniKey = strKey
End Property
Public Property Get Key() As String
    Key = iniKey
End Property
'读取INI文件中的条目
Public Function ReadItem(Optional ByVal strSection As String, Optional ByVal strKey As String)
    Dim sTemp As String * 256
    Dim nLen As Integer
    sTemp = Space$(256)
    '如果没有指定参数则按属性设置进行
    If Len(strSection) > 0 Then
       iniSec = strSection
    End If
    If Len(strKey) > 0 Then
       iniKey = strKey
    End If
    nLen = GetPrivateProfileString(iniSec, iniKey, vbNullString, sTemp, 255, iniFile)
    ReadItem = Left$(sTemp, nLen)
End Function
'将指定信息写入INI文件
Public Function WriteItem(ByVal value As String, Optional ByVal strSection As String, Optional ByVal strKey As String)
    
    Dim x As Long, Buff As String * 256, i As Integer
    
    'INI文件中的字符串必须以字符CHr(0)结尾
    Buff = value + Chr(0)
    If Len(strSection) > 0 Then
       iniSec = strSection
    End If
    If Len(strKey) > 0 Then
       iniKey = strKey
    End If
    x = WritePrivateProfileString(iniSec, iniKey, Buff, iniFile)
    If x = 0 Then MsgBox "ini文件写入错误!", , ""
    
End Function


这个代码在读写ini文件时有字数限制.
怎么把它改成无限制的???

作者: hack_bxc   发布时间: 2011-12-21

Dim sTemp As String * 512
  Dim nLen As Integer
  sTemp = Space$(512)

.
.
nLen = GetPrivateProfileString(iniSec, iniKey, vbNullString, sTemp, 512, iniFile)

---
Dim x As Long, Buff As String * 512, i As Integer

作者: chinaboyzyq   发布时间: 2011-12-21