Attribute VB_Name = "modPacketFormatting"
Option Explicit

Public Function CreateInt16(ByVal Value As Integer) As String
    Dim tmp As String * 2
    CopyMemory ByVal tmp, Value, 2
    CreateInt16 = tmp
End Function
Public Function CreateInt32(ByVal Value As Long) As String
    Dim tmp As String * 4
    CopyMemory ByVal tmp, Value, 4
    CreateInt32 = tmp
End Function
Public Function ExtractInt16(ByVal Data As String) As Integer
    Dim tmp As Integer
    CopyMemory tmp, ByVal Left$(Data, 2), 2
    ExtractInt16 = tmp
End Function
Public Function ExtractInt32(ByVal Data As String) As Long
    Dim tmp As Long
    CopyMemory tmp, ByVal Left$(Data, 4), 4
    ExtractInt32 = tmp
End Function
Public Function ExtractInt64(ByVal Data As String) As Currency
    Dim tmp As Currency
    CopyMemory tmp, ByVal Left$(Data, 8), 8
    ExtractInt64 = tmp
End Function
Public Function ExtractFT(ByVal Data As String) As FILETIME
    Dim tmp As FILETIME
    CopyMemory tmp, ByVal Left$(Data, 8), 8
    ExtractFT = tmp
End Function
Public Function GetQWORD(S As String) As String
    Dim rVal As FILETIME
    CopyMemory rVal, ByVal S, 8
    Dim sVal As String * 8
    CopyMemory ByVal sVal, rVal, 8
    GetQWORD = sVal
End Function
Public Function ByteToHex(ByVal Flags As Byte) As String
    ByteToHex = CStr("0x" & Right$(String$(2, "0") & CStr(Hex$(Flags)), 2))
End Function
Public Function LongToHex(ByVal Flags As Long) As String
    LongToHex = CStr("0x" & Right$(String$(8, "0") & CStr(Hex$(Flags)), 8))
End Function
Public Function StrToInt32(ByVal sTag As String) As Long
    Dim Result As Long
    sTag = sTag & String$(4 - Len(sTag), vbNullChar)
    sTag = StrReverse$(sTag)
    CopyMemory Result, ByVal sTag, 4
    StrToInt32 = Result
End Function
Public Function StrToHex(ByVal str As String) As String
    If LenB(str) = 0 Then Exit Function
    Dim i As Integer, Temp As String, hexTemp As String
    For i = 1 To Len(str)
        hexTemp = CStr(Hex$(Asc(Mid$(str, i, 1))))
        If Len(hexTemp) = 1 Then hexTemp = "0" & hexTemp
        Temp = Temp & hexTemp & Space$(1)
    Next i
    StrToHex = Left$(Temp, Len(Temp) - 1)
End Function

