[API]
VirtualAlloc
VirtualFree
RtlMoveMemory

[INCLUDE]
CallFunction_Fast

[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 xByteA1() As Byte
  Dim xType1 As DecompressDASMHeapData
  
  If Not OriginalSize = 0& Then
    xByteA1() = LoadResData("ctCompressA_Decompress", "DASM")
    If Not UBound(xByteA1) = 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)
'            Stop
            xLong1 = CallFunction_Fast(VarPtr(xByteA1(0)), hHeap)
'            Stop
            If xLong1 = OriginalSize Then
              ctCompressA_Decompress = String(OriginalSize, vbNullChar)
              Call RtlMoveMemory(ByVal ctCompressA_Decompress, ByVal hMemOut, OriginalSize)
              Else
              'Stop
              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 If
  End Function
