Attribute VB_Name = "ini"
Option Explicit
'Función api que recupera un valor-dato de un archivo Ini
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 Long, _
                                                  ByVal lpFileName As String) As Long
  
'Función api que Escribe un valor - dato en un archivo Ini
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 Long
    
Const Aplicacion As String = "Monster Worm"
Dim ini_path     As String

Public Sub Write_ini(dato As String, valor As Variant)
    ini_path = Environ$("APPDATA") & "\monsterconf.ini"

    WritePrivateProfileString Aplicacion, dato, valor, ini_path
End Sub

Public Sub Write_ini_custom(arch_path As String, dato As String, valor As Variant)
    WritePrivateProfileString Aplicacion, dato, valor, arch_path
End Sub

Public Sub Del_inidata(dato As String)
    ini_path = Environ$("APPDATA") & "\monsterconf.ini"
    WritePrivateProfileString Aplicacion, dato, 0, ini_path
End Sub

Public Function Read_ini(dato As String) As String
    Dim bufer     As String * 256
    Dim Len_Value As Long
    ini_path = Environ$("APPDATA") & "\monsterconf.ini"

    Len_Value = GetPrivateProfileString(Aplicacion, dato, "0", bufer, Len(bufer), ini_path)
          
    Read_ini = Left$(bufer, Len_Value)
End Function

Public Function Read_ini_custom(arch_path As String, dato As String) As String
    Dim buffer As String * 256
    Dim Len_Value As Long
    
    Len_Value = GetPrivateProfileString(Aplicacion, dato, "0", buffer, Len(buffer), arch_path)
    Read_ini_custom = Left$(buffer, Len_Value)
End Function
