SafeArrayCopyData

HRESULT SafeArrayCopyData( 
  SAFEARRAY FAR*  psaSource,  
  SAFEARRAY FAR* FAR*  psaTarget  
);
 

Copies the source array to the target array after releasing any resources in the target array. This is similar to SafeArrayCopy, except that the target array has to be set up by the caller. The target is not allocated or reallocated.

Parameters

psaSource
The safe array from which to be copied.
psaTarget
On exit, the array referred to by psaTarget contains a copy of the data in psaSource.

Return Value

The return value obtained from the returned HRESULT is one of the following.

Return value Meaning
S_OK Success.
E_INVALIDARG The argument psa was not a valid safearray descriptor.
E_OUTOFMEMORY Insufficient memory to create the copy.

Comments

Visual Basic for Applications and Automation use the same set of rules with cases in which the size or types of source and destination arrays do not match. The rules of Visual Basic are described in the following comments.

Array Assignment

In general, VBA5.0 supports array assignment.

Dim lhs(1 To 10) As Integer
Dim rhs(1 To 10) As Integer

lhs = rhs

When the number of dimensions, the size of those dimensions, and the element types match, data types are differentiated based on the following factors:

The following table shows what happens when the number of dimensions, size of the dimension, and element types do not match:

Fixed-size, left side Number of dimensions Dimensions match What happens
No Yes or No Yes or No Success. If necessary, the left side is resized to the size of the right side.
Yes No Failure.
Yes Yes No Treated in same manner as fixed-length strings.

If the right side has more elements than the left side, the assignment succeeds and the extra elements have no effect. If the left side has more elements than the right side, the assignment succeeds and the unaffected elements of the left side are zero-, null-, or empty-filled, depending on the types of the elements.

Yes Yes Yes Success.

See Also

SysAllocStringLen, VariantCopy, VariantCopyInd