CSDN博客

img 40Star

在.net中读写INI文件

发表于2002/10/20 9:18:00  1109人阅读

分类: Visual Basic .net

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

0 0

相关博文

我的热门文章

img
取 消
img