- 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.