- 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)'写
VB 使用API读写INI
最新推荐文章于 2021-10-11 10:49:34 发布