在.net中读写INI文件

80酷酷网    80kuku.com

  net中读写ini文件和Vb6中的做法是一致的,唯一注意的一点是Api声明中的Long型变量要改为int32类型在.net中
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strIni As String
strIni = New String(" ", 100)
GetPrivateProfileString("AppName", "KeyA", "", strIni, 100, "C:\a.ini")
WritePrivateProfileString("AppName", "KeyB", "MyValue", "C:\a.ini")
MsgBox(strIni)
End Sub

这段代码在.net + Win2000中调试通过

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: