WritePrivateProfileString 是一個函數,它用于向INI文件中寫入或修改一個鍵值對。
它的用法如下: WritePrivateProfileString(section, key, value, filename)
參數說明:
函數的功能是將指定的鍵值對寫入或修改INI文件中指定節下的指定鍵名處。如果指定的節或鍵名不存在,則函數會創建它們。
示例:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("kernel32")>
Private Shared Function WritePrivateProfileString(section As String, key As String, value As String, filePath As String) As Integer
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim section As String = "MySection"
Dim key As String = "MyKey"
Dim value As String = "MyValue"
Dim filePath As String = "C:\path\to\my.ini"
WritePrivateProfileString(section, key, value, filePath)
End Sub
End Class
上述示例代碼中,當按鈕被點擊時,會將 “MySection” 節下的 “MyKey” 鍵的值設置為 “MyValue”,并寫入到 “C:\path\to\my.ini” 文件中。