您的位置:首页 > 编程语言 > VB

VB 使用API读写INI

2008-08-24 11:33 190 查看
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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _

(ByVal LpApplicationName As String, _

ByVal LpKeyName As Any, _

ByVal lpString As Any, _

ByVal lpFileName As String) As Long

'获取INI配置文件

Public Function GetINI(ByVal LpApplicationName As String, ByVal LpKeyName As String) As String

Dim retVal As Long

Dim Value As String

Value = Space(128)

retVal = GetPrivateProfileString(LpApplicationName, LpKeyName, "", Value, Len(Value), Replace(App.Path & "/Config.ini", "//", "/"))

GetINI = Left(Trim(Value), Len(Trim(Value)) - 1)

End Function

'写INI配置文件

Public Sub WriteINI(ByVal LpApplicationName As String, ByVal LpKeyName As String, ByVal Value As String)

Dim retVal As Long

retVal = WritePrivateProfileString(LpApplicationName, LpKeyName, Value, Replace(App.Path & "/Config.ini", "//", "/"))

End Sub

Form1.Text1 = GetINI("基本设置", "Content")'读

Call WriteINI("基本设置", "Content", Form1.Text1)'写
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: