Attribute VB_Name = "Mod1"
Option Explicit

Public Declare Sub CopyMemoryX Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)
Public Declare Sub CopyMemory3 Lib "kernel32" Alias "RtlMoveMemory" (ByVal Dest As Long, ByVal Source As Long, ByVal cbCopy As Long)
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

'Public Declare Function GetTickCount Lib "kernel32" () As Long

'Public Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long
'Public Declare Function inet_ntoa Lib "wsock32.dll" (ByVal inn As Long) As Long

'SocketType property values
Public Const SOCK_TCP = 1  'PF_INET, SOCK_TCP, IPPROTO_TCP)
Public Const SOCK_UDP = 2  'PF_INET, SOCK_UDP, IPPROTO_UDP)
Public Const SOCK_IP = 3   'PF_INET, SOCK_UDP, IPPROTO_IP)

Public Function FillZero(ByVal RawText As String, DesiredLength As Long) As String
    If DesiredLength <= Len(RawText) Then
        FillZero = Left(RawText, DesiredLength)
    Else
        FillZero = RawText & String(DesiredLength - Len(RawText), Chr(0))
    End If
End Function

Public Function FillX(ByVal RawText As String, ByVal DesiredLength As Long, ByVal CharX As String) As String
    If DesiredLength <= Len(RawText) Then
        FillX = Left(RawText, DesiredLength)
    Else
        FillX = RawText & String(DesiredLength - Len(RawText), CharX)
    End If
End Function

Public Function TrimZero(ByVal RawText As String) As String
    Dim L As Long
    L = InStr(RawText, Chr(0))
    If L > 0 Then
        TrimZero = Left(RawText, L - 1)
    Else
        TrimZero = RawText
    End If
End Function

Public Function StringToInt(ByVal RawText As String) As Integer
    Dim I As Integer
    Call CopyMemoryX(I, ByVal RawText, 2)
    StringToInt = I
End Function

Public Function StringToLong(ByVal RawText As String) As Long
    Dim L As Long
    Call CopyMemoryX(L, ByVal RawText, 4)
    StringToLong = L
End Function

Public Function LongToString(L As Long) As String
    Dim S4 As String
    S4 = Space(4)
    Call CopyMemoryX(ByVal S4, L, 4)
    LongToString = S4
End Function

Public Function IntToString(I As Integer) As String
    Dim S2 As String
    S2 = Space(2)
    Call CopyMemoryX(ByVal S2, I, 2)
    IntToString = S2
End Function

Public Function GetProfileString(Section As String, Key As String) As String
    Dim S As String * 255
    Dim L As Long
    L = GetPrivateProfileString(Section, Key, "", S, 255, App.Path + "\bot.ini")
    If L = 0 Then
        MsgBox "Error in " & App.Path & "\BOT.INI" & vbCrLf & "The " & Chr(34) & Key & Chr(34) & " key is missing at section " & Chr(34) & "[" & Section & "]" & Chr(34) & vbCrLf & "Edit the BOT.INI file and correct the error.", vbExclamation, "Error"
        End
    End If
    GetProfileString = Left(S, L)
End Function

'Public Sub WriteProfileString(Section As String, Key As String, Value As String)
'    WritePrivateProfileString Section, Key, Value, App.Path + "\bot.ini"
'End Sub

'Public Function IPLongToString(IPLong As Long) As String
'    Dim PtrMem   As Long
'    Dim Char     As Byte
'    Dim Cont     As Integer
'    Dim IPString As String
'    '
'    'Translates IP in long format to IP in string format.
'    '
'    IPLongToString = ""
'    '
'    'If Sw_WSAStarted = False Then
'    '    If WSAStart = SOCK_ERROR Then
'    '        Exit Function
'    '    End If
'    'End If
'    '
'    PtrMem = inet_ntoa(IPLong)
'    '
'    If PtrMem = 0 Then
'        Exit Function
'    End If
'    '
'    Do
'        CopyMemory3 VarPtr(Char), PtrMem, 1
'        If Char = 0 Then
'            IPLongToString = IPString
'            Exit Function
'        Else
'            IPString = IPString & Chr(Char)
'            PtrMem = PtrMem + 1
'            Cont = Cont + 1: If Cont = 256 Then Exit Function
'        End If
'    Loop
'End Function
'
'Public Function IPStringToLong(IPString As String) As Long
'    Dim IPLong As Long
'    '
'    'Translates IP in string format to IP in long format.
'    '
'    IPStringToLong = 0
'    '
'    'If Sw_WSAStarted = False Then
'    '    If WSAStart = -1 Then
'    '        Exit Function
'    '    End If
'    'End If
'    '
'    IPLong = inet_addr(IPString)
'    If IPLong <> 0 Then
'        IPStringToLong = IPLong
'    End If
'End Function
'
