明辉站/技术开发/内容

在.net中读写INI文件 40Star(原作)

技术开发2023-08-10 阅读
[摘要]在.net中读写INI文件40Star(原作)在.net中读写ini文件和Vb6中的做法是一致的,唯一注意的一点是Api声明中的Long型变量要改为int32类型在.net中Private Declare Function GetPrivateProfileString Lib "ker...
在.net中读写INI文件40Star(原作)

在.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中调试通过

……

相关阅读