Share via


VariantCopy

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function frees the destination variant and makes a copy of the source variant.

Syntax

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

Parameters

  • pvargDest
    [out] Pointer to the VARIANTARG to receive the copy.
  • pvargSrc
    [in] Pointer to the VARIANTARG to be copied.

Return Value

Returns the HRESULT values shown in the following table.

Value Description

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

An argument is invalid.

Remarks

Passing invalid (and under some circumstances NULL) pointers to this function causes an unexpected termination of the application.

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 pvargSrc is 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.

Requirements

Header oleauto.h
Library oleaut32.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

Automation Functions
VARIANT and VARIANTARG
VariantClear