Module INI
    Private Declare Ansi Function GetPrivateProfileString _
      Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
      (ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, ByVal lpDefault As String, _
      ByVal lpReturnedString As System.Text.StringBuilder, _
      ByVal nSize As Integer, ByVal lpFileName As String) _
      As Integer
    Private Declare Ansi Function WritePrivateProfileString _
      Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
      (ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, ByVal lpString As String, _
      ByVal lpFileName As String) As Integer
    Private Declare Ansi Function GetPrivateProfileInt _
      Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
      (ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, ByVal nDefault As Integer, _
      ByVal lpFileName As String) As Integer
    Private Declare Ansi Function FlushPrivateProfileString _
      Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
      (ByVal lpApplicationName As Integer, _
      ByVal lpKeyName As Integer, ByVal lpString As Integer, _
      ByVal lpFileName As String) As Integer

    Public Function GetString(ByVal strFilename As String, ByVal Section As String,
      ByVal Key As String, ByVal [Default] As String) As String

        GetString = ""

        Dim intCharCount As Integer
        Dim objResult As New System.Text.StringBuilder(256)
        intCharCount = GetPrivateProfileString(Section, Key,
           [Default], objResult, objResult.Capacity, strFilename)
        If intCharCount > 0 Then GetString =
           Left(objResult.ToString, intCharCount)


        'This should probably be commented out if used for another program!
        If LoadedROM <> "" Then
            If GetString = "" And GetINIFileLocation() = strFilename Then
                OutPutError("Error! " & Key & " is missing for ROM " & Section & "!")
            End If
        End If

    End Function

    Public Function WriteString(ByVal strFilename As String, ByVal Section As String, _
      ByVal Key As String, ByVal Value As String)
        WritePrivateProfileString(Section, Key, Value, strFilename)
        Flush(strFilename)
        WriteString = ""
    End Function

    Private Sub Flush(ByVal thing As String)
        FlushPrivateProfileString(0, 0, 0, thing)
    End Sub

End Module
