Allocates a memory buffer and copies the contents of an array.
BinaryAllocArray( array )
(a) array: Specifies an array.
(i) handle: Returns a handle to a buffer that contains a copy of the array.
This function is intended to convert binary data from an array of binary data, such as an image returned by a OLE/COM function to it's original form, so that it may be subsequently written to disk.
Use this function to allocate a memory buffer that contains a copy of the contents of an array. The memory buffer’s size is automatically set to hold a copy of the entire array.
The array elements must be integers, floating point numbers or one of the COM Automation types from the list below:
Variant-type |
Value to specify |
I1 |
A 1-byte character value |
I2 |
A 2-byte integer value |
I4 |
A 4-byte integer value |
R4 |
32-bit IEEE floating point value. |
R8 |
64-bit IEEE floating point value. |
BOOL |
A Boolean (True/False) value |
CY |
A currency value, specified as a string in the form "#CURRENCY:value |
DATE |
A date/time value, specified as a string in Ymd or YmdHms format |
UI1 |
1-byte unsigned integer. |
UI2 |
2-byte unsigned integer. |
UI4 |
4-byte unsigned integer. |
UI8 |
8-byte unsigned integer. |
INT |
4-byte signed integer value (equivalent to I4). |
UINT |
4-byte unsigned integer (equivalent to VT_UI4). |
DECIMAL |
A decimal value, specified as a string in the form "#DECIMAL:value |
Notes:
You can use the ObjectTypeGet function to determine the type of a COM array element.
All array elements must be of the exact same type. For example, the function will fail, if the array elements are both integers and floating point numbers.
Text array elements are not supported.
If you want to create an integer array from scratch where the each array element is treated as a one or two byte value use ObjectType with the first parameter set to "U1" or "U2" respectively. For example,
aBytes = ArrDimension(2)
aBytes[0] = ObjectType("U1",65 )
aBytes[1] = ObjectType("U1", 90)
will create a byte array with two elements.
This function only accepts single dimensional arrays.
Because the 64-bit Windows COM APIs do not support arrays larger that 2GB, this function will not create buffers larger than 2GBs on 64-bit systems.
This example uses the BinaryAllocArray function To copy an image To a binary buffer so that it can be saved To a local file. The image is retrieved from a host internet site as an array of bytes or "ARRAY|U1" as returned By ObjectTypeGet. ; Create a local file name. path = "c:\temp\" imagefile = "http://www.google.com/images/logo.gif" localname = StrCat(path, ItemExtract(ItemCount(imagefile, "/"), imagefile, "/")) ; Get an image from the internet. WinHttpReq = ObjectCreate("WinHttp.WinHttpRequest.5.1") ; Windows XP SP 1 WinHttpReq.Open("GET", imagefile, @FALSE) WinHttpReq.Send x = WinHttpReq.ResponseBody ; Convert to binary buffer. BinBuf = BinaryAllocArray(x) ; Write binary buffer to a file. BinaryWrite(BinBuf, localname) ; Cleanup WinHttpReq = 0 BinaryFree(BinBuf)
BinaryAlloc, BinaryWrite, Binary Operations, ObjectType, ObjectTypeGet