Reading from an INI file

后端 未结 1 412
生来不讨喜
生来不讨喜 2021-01-19 09:37

I find it very easy to write to a INI file, but am having some trouble in retrieving the data from an already created INI file.

I am using this function:

<         


        
相关标签:
1条回答
  • 2021-01-19 09:48

    Going to the Pinvoke.Net Web site and modifying their example worked, their Function declaration is different.

    Modified Example

    Imports System.Runtime.InteropServices
    Imports System.Text
    Module Module1
        Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
                ByVal lpKeyName As String, _
                ByVal lpDefault As String, _
                ByVal lpReturnedString As StringBuilder, _
                ByVal nSize As Integer, _
                ByVal lpFileName As String) As Integer
    
        Sub Main()
    
            Dim res As Integer
            Dim sb As StringBuilder
    
            sb = New StringBuilder(500)
            res = GetPrivateProfileString("testApp", "KeyName", "", sb, sb.Capacity, "c:\temp\test.ini")
            Console.WriteLine("GetPrivateProfileStrng returned : " & res.ToString())
            Console.WriteLine("KeyName is : " & sb.ToString())
            Console.ReadLine();
    
        End Sub
    End Module
    
    0 讨论(0)
提交回复
热议问题