Passing Variant Parameters in OLE Automation

ID: Q104960

2.00 4.00 | 3.50 3.51

WINDOWS   | WINDOWS NT
kbole kbprg kbwebcontent

The information in this article applies to:

A variant must be initialized using VariantInit after creation and before it is passed to a function. A variant with a valid value must be cleared using VariantClear before a new value is assigned to it.

A variant must be passed to or from a function in a valid state and the contents of the variant must be correctly freed. This requires that the following be done:

1. On creation of a variant, call VariantInit before passing it to a

   function.

2. A function that is passed a variant should clear it using
   VariantClear to free the previous contents before assigning it a
   new value.

VariantInit sets the vt field of the VARIANT (or VARIANTARG) structure to VT_EMPTY but does not free the contents of the variant. VariantClear frees the contents of the variant depending on the current value of the vt field and then sets the vt field to VT_EMPTY.

Passing an uninitialized variant to a function is a common error. This may cause problems when the VariantClear call in the function tries to free the contents of the uninitialized variant based on the undefined value of the vt field.

Additional reference words: 2.00 2.01 3.50 4.00 KBCategory: kbole kbprg kbwebcontent KBSubcategory: LeTwoAto

Keywords          : LeTwoAto 
Version           : 2.00 4.00 | 3.50 3.51
Platform          : NT WINDOWS

Last Reviewed: August 6, 1996