Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Public Class clsReg
    Inherits System.ComponentModel.Component

    <DllImport("coredll.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function GetPrivateProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As UInt32, ByVal lpFileName As String) As UInt32
    End Function

    <DllImport("coredll.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function WritePrivateProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As UInt32
    End Function
    Public Function fGetIniValueOLD(ByVal pProFile As String, ByVal pSection As String, ByVal pKey As String) As String
        Dim wBuf As StringBuilder = New StringBuilder(256)
        Dim wnum As UInt32
        Dim wPath As String
        Dim intCnt As Integer

        wPath = pProFile
        wnum = GetPrivateProfileString(pSection, pKey, "", wBuf, Convert.ToUInt32(wBuf.Capacity), wPath)
        If wBuf.Length = 0 Then fGetIniValueOLD = "" : Exit Function

        fGetIniValueOLD = wBuf.ToString
    End Function

    Public Function fGetIniValue(ByVal pProFile As String, ByVal pSection As String, ByVal pKey As String) As String

        Dim sr As StreamReader = New StreamReader(pProFile)
        Dim sectionName = pSection
        Dim result As String = ""

        Dim a As String
        Dim st As String()
        Dim i As Integer = 0
        Dim isSection As Boolean = False

        Try

            Do
                a = sr.ReadLine


                If a <> String.Empty Then


                    If a.Contains(pSection) Then
                        isSection = True
                    End If


                    st = a.Split(New Char() {"="c})

                    If st.Length = 2 Then
                        If st(0) = pKey And isSection = True Then
                            Return st(1)
                        End If
                    End If
                End If

            Loop Until a Is Nothing

            sr.Close()

            Return result



        Catch ex As Exception
            Return ""
        End Try

    End Function

    Public Function fPutIniValue(ByVal pProFile As String, ByVal pSection As String, ByVal pKey As String, ByVal pBuf As String) As Boolean
        Dim wPath As String
        Dim wnum As UInt32

        wPath = pProFile
        wnum = WritePrivateProfileString(pSection, pKey, pBuf, wPath)

        fPutIniValue = False
    End Function
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Public Sub New()
        MyBase.new()
    End Sub

End Class
