怎么读写INI文件?

intocsdn 2003-11-14 06:31:00
请教:
我想自己建一个INI文件,该用什么API函数?怎么进行读、写?
...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
intocsdn 2003-11-16
  • 打赏
  • 举报
回复
非常感谢,我已经会用了。
lsm0959 2003-11-14
  • 打赏
  • 举报
回复
getprivateprofilestring
getprivateprofileint

writeprivateprofilestring
writeprivateprofileint

自己的INI基本上就这几个,参数很简单,一看就明白了
zt31 2003-11-14
  • 打赏
  • 举报
回复
学习ing
subzero 2003-11-14
  • 打赏
  • 举报
回复
这个问题最近问的还真不少

Public File As String

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 Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal FileName As String) As Integer

Sub DeleteSection(ByVal Section As String)
Dim retval As Integer
retval = WritePrivateProfileString(Section, 0&, "", File)
End Sub

Public Function SaveSetting(ByVal Section$, ByVal Key$, ByVal Value$)
Dim retval As Integer
SaveSetting = WritePrivateProfileString(Section$, Key$, Value$, File)
End Function

Public Function GetSetting(ByVal Section As String, ByVal KeyName As String) As String
Dim retval As Integer
Dim t As String * 255

retval = GetPrivateProfileString(Section, KeyName, "unknown value", t, Len(t), File)

If retval > 0 Then
GetSetting = Left$(t, retval)
Else
GetSetting = ""
End If
End Function

Public Function GetSection(ByVal Section As String, KeyArray() As String) As Integer
Dim retval As Integer
Dim t As String * 2500
Dim lastpointer As Integer
Dim nullpointer As Integer
Dim ArrayCount As Integer
Dim keystring As String

ReDim KeyArray(0)

retval = GetPrivateProfileString(Section, 0&, "", t, Len(t), File)

If retval > 0 Then
nullpointer = InStr(t, Chr$(0))
lastpointer = 1
Do While (nullpointer <> 0 And nullpointer > lastpointer + 1)
keystring = Mid$(t, lastpointer, nullpointer - lastpointer)
ArrayCount = ArrayCount + 1
ReDim Preserve KeyArray(ArrayCount)
KeyArray(ArrayCount) = keystring
lastpointer = nullpointer + 1
nullpointer = InStr(nullpointer + 1, t, Chr$(0))
Loop
End If
GetSection = ArrayCount
End Function
rainstormmaster 2003-11-14
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2450/2450394.xml?temp=.309704

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧