Compresses a buffer with specified compression format and engine type.
#Include <WinAPIEx.au3>
_WinAPI_CompressBuffer ( $pUncompressedBuffer, $iUncompressedSize, $pCompressedBuffer, $iCompressedSize [, $iFormatAndEngine] )
$pUncompressedBuffer | A pointer to a caller-allocated buffer that contains the data to be compressed. |
$iUncompressedSize | The size of the uncompressed buffer, in bytes. |
$pCompressedBuffer | A pointer to a caller-allocated buffer that receives the compressed data. |
$iCompressedSize | The size of the compressed buffer, in bytes. |
$iFormatAndEngine | [可选参数] A bitmask that specifies the compression format and engine type. This parameter must be set to a valid bitwise OR combination of one format type and one engine type. $COMPRESSION_FORMAT_LZNT1 $COMPRESSION_FORMAT_XPRESS $COMPRESSION_FORMAT_XPRESS_HUFF $COMPRESSION_ENGINE_STANDARD $COMPRESSION_ENGINE_MAXIMUM |
Success | The size of the compressed data stored in compressed buffer, in bytes. |
Failure | 0 and sets the @error flag to non-zero, @extended flag may contain the NTSTATUS code. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $pBuffer[2], $Data, $Size
; Create compressed and uncompressed buffers
For $i = 0 To 1
$pBuffer[$i] = _WinAPI_CreateBuffer(1024)
Next
; Compress binary data
$Data = Binary('0x00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF')
$Size = BinaryLen($Data)
DllStructSetData(DllStructCreate('byte[' & $Size & ']', $pBuffer[0]), 1, $Data)
$Size = _WinAPI_CompressBuffer($pBuffer[0], $Size, $pBuffer[1], 1024, BitOR($COMPRESSION_FORMAT_LZNT1, $COMPRESSION_ENGINE_MAXIMUM))
If Not @error Then
ConsoleWrite('Compressed: ' & DllStructGetData(DllStructCreate('byte[' & $Size & ']', $pBuffer[1]), 1) & @CR)
EndIf
; Decompress data
$Size = _WinAPI_DecompressBuffer($pBuffer[0], 1024, $pBuffer[1], $Size)
If Not @error Then
ConsoleWrite('Uncompressed: ' & DllStructGetData(DllStructCreate('byte[' & $Size & ']', $pBuffer[0]), 1) & @CR)
EndIf
; Free memory
For $i = 0 To 1
_WinAPI_FreeMemory($pBuffer[$i])
Next