Passing Variant Parameters in OLE Automation (104960)
The information in this article applies to:
- Microsoft OLE Libraries for Windows and Win32s 2.0
- Microsoft OLE Libraries, when used with:
- the operating system: Microsoft Windows NT 3.5
- the operating system: Microsoft Windows NT 3.51
- the operating system: Microsoft Windows NT 4.0
- the operating system: Microsoft Windows 95
- the operating system: Microsoft Windows 2000
This article was previously published under Q104960
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: - On creation of a variant, call VariantInit before passing it to a
function.
- 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.
Modification Type: | Major | Last Reviewed: | 12/3/2003 |
---|
Keywords: | kbprogramming KB104960 |
---|
|