VariantCopy Function

Frees the destination variant and makes a copy of the source variant.

HRESULT VariantCopy(
  VARIANTARG   *pvargDest,
  VARIANTARG   *pvargSrc
);

pvargDest

Pointer to the VARIANTARG to receive the copy.

pvargSrc

Pointer to the VARIANTARG to be copied.

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

Value

Meaning

S_OK

Success.

DISP_E_ARRAYISLOCKED

The variant contains an array that is locked.

DISP_E_BADVARTYPE

The source and destination have an invalid variant type (usually uninitialized).

E_OUTOFMEMORY

Memory could not be allocated for the copy.

E_INVALIDARG

One of the arguments is invalid.

First, free any memory that is owned by pvargDest, such as VariantClear (pvargDest must point to a valid initialized variant, and not simply to an uninitialized memory location). Then pvargDest receives an exact copy of the contents of pvargSrc.

If pvargSrc is a VT_BSTR, a copy of the string is made. If pvargSrcis a VT_ARRAY, the entire array is copied. If pvargSrc is a VT_DISPATCH or VT_UNKNOWN, AddRef is called to increment the object's reference count.

If the variant to be copied is a COM object that is passed by reference, the vtfield of the pvargSrcparameter is VT_DISPATCH | VT_BYREF or VT_UNKNOWN | VT_BYREF. In this case, VariantCopy does not increment the reference count on the referenced object. Because the variant being copied is a pointer to a reference to an object, VariantCopy has no way to determine if it is necessary to increment the reference count of the object. It is therefore the responsibility of the caller to call IUnknown::AddRef on the object or not, as appropriate.

NoteNote

The VariantCopy method is not threadsafe.

Show:
© 2014 Microsoft