2.2.1.1.1.3 SAFEARRAY
SAFEARRAY is used to pass multidimensional arrays. The structure contains array size information as well as the data in the array.
|
|
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
3 |
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cDims |
fFeatures |
||||||||||||||||||||||||||||||
cbElements |
|||||||||||||||||||||||||||||||
Rgsabound (variable) |
|||||||||||||||||||||||||||||||
... |
|||||||||||||||||||||||||||||||
vData (variable) |
|||||||||||||||||||||||||||||||
... |
cDims (2 bytes): Unsigned 16-bit integer, indicating the number of dimensions of the multidimensional array.
fFeatures (2 bytes): A 16-bit bitfield. The values represent features defined by upper-layer applications and MUST be ignored.
cbElements (4 bytes): A 32-bit unsigned integer specifying the size of each element of the array.
Rgsabound (variable): An array that contains one SAFEARRAYBOUND structure per dimension in the SAFEARRAY. This array has the left-most dimension first and the right-most dimension last.
vData (variable): A vector of marshaled items of a particular type, indicated by the vType of the containing CBaseStorageVariant, with the bit 0x2000 cleared.
-
vData is marshaled similarly to VT_VECTOR, as specified in section 2.2.1.1.1.2, but the number of items is not stored in front of the vector. Rather, the number of items is calculated by multiplying the cElements value with all safe array bounds given in the Rgsabound field. Elements are stored in a vector in order of dimensions, iterating beginning with the right-most dimension.
-
The following table visually represents a sample two-dimensional array. The first dimension has cElements equal to 4 (represented horizontally) and lLbound equal to 0. The second dimension has cElements equal to 2 (represented vertically) and lLbound equal to 0.
-
cElement 0
cElement 1
cElement 2
cElement 3
0x00000001
0x00000002
0x00000003
0x00000005
0x00000007
0x00000011
0x00000013
0x00000017
-
Using the previous diagram, vData will contain the following sequence: 0x00000001, 0x00000007, 0x00000002, 0x00000011, 0x00000003, 0x00000013, 0x00000005, 0x00000017 (iterating through the rightmost dimension first, and then incrementing the next dimension). The preceding Rgsabound (which records cElements and lLbound) would be: 0x00000004, 0x00000000, 0x00000002, and 0x00000000.