[LEGAL]
Huffman

[API]
VirtualAlloc
VirtualProtect
VirtualFree
RtlMoveMemory
CallWindowProcA

[INCLUDE]

[ASSEMBLY]
ctCompressA_Decompress

[DEFINE]
Private Const DecompressDASMSize As Long = &H4C38&
Private Type DecompressDASMHeapData
  ptrDataIn As Long
  ptrDataOut As Long
  ProgressHandler As Long
  ProgressControl As Long
  ProgressStart As Long
  ProgressTotal As Long
  ProgressQueue As Long
  End Type
Private Const DecompressDASMHeapDataSize As Long = 28&

[CODE]
Public Function ctCompressA_Decompress(ByRef Data As String, ByVal OriginalSize As Long, Optional ByVal ProgressHandler As Long, Optional ByVal ProgressControl As Long = 0&, Optional ByVal ProgressStart As Long = 0&, Optional ByVal ProgressTotal As Long = 0&, Optional ByVal ProgressQueue As Long = 0&) As String
  Dim hHeap As Long
  Dim hMemIn As Long
  Dim hMemOut As Long
  Dim xLong1 As Long
  Dim xType1 As DecompressDASMHeapData
  
  If Not (Len(Data) = 0& Or OriginalSize = 0& Or ctCompressA_Decompress_Exe = 0&) Then
    hHeap = VirtualAlloc(0&, DecompressDASMSize, &H1000&, 4&)
    If hHeap Then
      hMemIn = VirtualAlloc(0&, Len(Data), &H1000&, 4&)
      If hMemIn Then
        hMemOut = VirtualAlloc(0&, OriginalSize, &H1000&, 4&)
        If hMemOut Then
          Call RtlMoveMemory(ByVal hMemIn, ByVal Data, Len(Data))
          Data = ""
          With xType1
            .ptrDataIn = hMemIn
            .ptrDataOut = hMemOut
            .ProgressHandler = ProgressHandler
            .ProgressControl = ProgressControl
            .ProgressStart = ProgressStart
            .ProgressTotal = ProgressTotal
            .ProgressQueue = ProgressQueue
            End With
          Call RtlMoveMemory(ByVal hHeap, xType1, DecompressDASMHeapDataSize)
          xLong1 = CallWindowProcA(ctCompressA_Decompress_Exe, 0&, 0&, hHeap, 0&)
          If xLong1 = OriginalSize Then
            ctCompressA_Decompress = String(OriginalSize, vbNullChar)
            Call RtlMoveMemory(ByVal ctCompressA_Decompress, ByVal hMemOut, OriginalSize)
            Else
            ctCompressA_Decompress = ""
            End If
          Call VirtualFree(hMemOut, 0&, &H8000&)
          End If
        Call VirtualFree(hMemIn, 0&, &H8000&)
        End If
      Call VirtualFree(hHeap, 0&, &H8000&)
      End If
    End If
  End Function