Class VBUserDefinedTypeImage
The bytes a VBUserDefinedTypeValue occupies in memory, laid out by
VBUserDefinedTypeLayout — what an LSet between two UDT variables copies
(MS-VBAL §5.4.3.6).
public static class VBUserDefinedTypeImage
- Inheritance
-
VBUserDefinedTypeImage
- Inherited Members
Remarks
The specification says twice that this is implementation-defined: "the data in expression (as
stored in memory in an implementation-defined manner) is copied into bound-variable-expression
in an implementation-defined manner". What it does not say, and what every VBA program using
LSet on a UDT relies on, is that the copy reinterprets: the source's bytes are laid out by
the source's own type and read back through the destination's, which is how VBA fakes a union. So this is
a byte image and not a field-by-field assignment — between two UDTs of the same shape the two would agree,
and between different shapes only the byte image does what the program meant.
👉 These are memory widths, the ones LenB counts. They are not the widths the same value
takes in a record: VBUserDefinedTypeLayout's own remarks say why the two differ, and
RecordDataFormat is the other one.
Methods
Copy(VBUserDefinedTypeValue, VBUserDefinedTypeValue)
Copies source into destination as bytes
(MS-VBAL §5.4.3.6), reinterpreting them through the destination's own layout.
public static void Copy(VBUserDefinedTypeValue source, VBUserDefinedTypeValue destination)
Parameters
sourceVBUserDefinedTypeValueThe value read.
destinationVBUserDefinedTypeValueThe value written, field by field, in place.
Remarks
Only the bytes both types have are copied, as a copy between records of different sizes must be: a destination field that does not fit entirely inside the source's image is left at its declared type's default rather than being filled with half a value.
HoldsVariableLengthString(VBUserDefinedType)
Whether type has a variable-length String member, directly or in a user-defined type that it has as a member.
public static bool HoldsVariableLengthString(VBUserDefinedType type)
Parameters
typeVBUserDefinedTypeThe user-defined type to look into.
Returns
Remarks
A fixed-length String member is not one: its characters are in the record. A variable-length one is a pointer, and it is what
makes a byte copy of the record (LSet, MS-VBAL §5.4.3.6) unsafe in MS-VBA.
Of(VBUserDefinedTypeValue)
The memory image of value: each field's bytes at the offset its layout assigns,
and zeroes in the padding between them.
public static byte[] Of(VBUserDefinedTypeValue value)
Parameters
valueVBUserDefinedTypeValueThe value to lay out.
Returns
- byte[]
Remarks
A field with no byte representation of its own — a variable-length String, an object, an array,
a Variant — is a pointer in memory, and a pointer's bytes mean nothing to a process
that did not allocate them. Those bytes are left zero here and the values are carried across by
Copy(VBUserDefinedTypeValue, VBUserDefinedTypeValue) instead, which is the one place the reinterpretation can be done safely.