Jump to content

Variable Packing UDF

Recommended Posts

These functions pack/unpack variables to/from binary data. It is useful to save setting or preference into binary data, or transfer variables between different script, etc.


In my programs, I store all the sensitive setting in a single associative array. Use this to pack it, and then compress, encrypt, and save to file.


Supported type: Int, String, Binary, Ptr, Bool, Double, Default, 1D/2D Array, Associative Array (of my UDF).

Required (not included): and





#Include "VarPack.au3"
#Include "AssociativeArray.au3"
Func Example_Usage()
    Local $Array1D[5] = [1, "2", 3.3, Binary("0x44"), Ptr(5)]
    Local $Array2D[2][4] = [[$Array1D, False, True, Default], [Int(0/0), "", 3, 4]]
    Local $AA = AACreate()
    AAPut($AA, "123", 123)
    AAPut($AA, 456, Ptr(456))
    AAPut($AA, Binary("0x778899"), $Array2D)
    AAPut($AA, Int(0/0), $Array1D)
    Local $WhatToPack[3] = [$Array1D, $Array2D, $AA]
    Local $Binary1 = _VarPack($WhatToPack)
    Local $WhatUnpacked = _VarUnpack($Binary1)
    Local $Binary2 = _VarPack($WhatUnpacked)
    ConsoleWrite("Size of packed data: " & BinaryLen($Binary1) & @CRLF)
    ConsoleWrite("Variable unpack succeed: " & ($Binary1 = $Binary2) & @CRLF)
    Local $Data = AAGet($WhatUnpacked[2], Binary("0x778899"))
    $Data = $Data[0][0]
    $Data = $Data[4]
    ConsoleWrite("Try to read unpacked variable Ptr(5): " & $Data & @CRLF)



VarPack UDF.zip

Edited by Ward

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了


Link to post
Share on other sites

I'm sorry if I don't understand the purpose of this, but how is this different than a DllStruct?

This work on array, associative array, array in array, array in associative array, associative array in array, 2D array in array, etc...

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了


Link to post
Share on other sites

Very nice example, but I get an error

C:\VarPack.au3(71,49) : ERROR: _VarPack() called with Const or expression on ByRef-param(s).

$Data[$i] &= _VarPack(AAGet($Var, $Keys[$i]))


C:\VarPack.au3(27,26) : REF: definition of _VarPack().

Func _VarPack(ByRef $Var)


C:\VarPack.au3 - 1 error(s), 0 warning(s)

!>09:06:26 AU3Check ended.rc:2

And with forum upgrade your sign has become unreadable :graduated:

AutoIt X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to post
Share on other sites



Although AU3Check report it as error, however, the script can work without problem.

To avoid it report as error, may change the code

$Data[$i] &= _VarPack(AAGet($Var, $Keys[$i]))


Local $Keys = AAGet($Var, $Keys[$i])
$Data[$i] &= _VarPack($Keys)

But since both code work, is there any other reason to do the change except to let AU3Check happy?

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...