Passing Variant Parameters in OLE Automation

Last reviewed: August 5, 1996
Article ID: Q104960
The information in this article applies to:
  • Microsoft OLE Libraries for Windows and Win32s, version 2.0
  • Microsoft OLE Libraries, included with:

        - Microsoft Windows NT, versions 3.5 and 3.51
        - Microsoft Windows 95
    

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 5, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.