VB 使用API讀寫INI

  1. Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
  2.                         (ByVal LpApplicationName As String, _
  3.                         ByVal LpKeyName As Any, _
  4.                         ByVal lpDefault As String, _
  5.                         ByVal lpReturnedString As String, _
  6.                         ByVal nSize As Long, _
  7.                         ByVal lpFileName As StringAs Long
  8. Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
  9.                         (ByVal LpApplicationName As String, _
  10.                         ByVal LpKeyName As Any, _
  11.                         ByVal lpString As Any, _
  12.                         ByVal lpFileName As StringAs Long
  13. '獲取INI配置文件
  14. Public Function GetINI(ByVal LpApplicationName As StringByVal LpKeyName As StringAs String
  15.     Dim retVal As Long
  16.     Dim Value As String
  17.     Value = Space(128)
  18.     retVal = GetPrivateProfileString(LpApplicationName, LpKeyName, "", Value, Len(Value), Replace(App.Path & "/Config.ini""//", "/"))
  19.     GetINI = Left(Trim(Value), Len(Trim(Value)) - 1)
  20. End Function
  21. '寫INI配置文件
  22. Public Sub WriteINI(ByVal LpApplicationName As StringByVal LpKeyName As StringByVal Value As String)
  23.     Dim retVal As Long
  24.     retVal = WritePrivateProfileString(LpApplicationName, LpKeyName, Value, Replace(App.Path & "/Config.ini""//", "/"))
  25. End Sub
  26. Form1.Text1 = GetINI("基本設置""Content")'讀
  27. Call WriteINI("基本設置""Content", Form1.Text1)'寫
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章