Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/104960

From BetaArchive Wiki
Knowledge Base

Passing Variant Parameters in OLE Automation

Article ID: 104960

Article Last Modified on 12/3/2003


  • Microsoft OLE 2.0
  • Microsoft OLE 4.0, when used with:
    • Microsoft Windows NT 4.0
    • Microsoft Windows NT 3.51 Service Pack 5
    • Microsoft Windows NT 4.0
    • Microsoft Windows 95
    • Microsoft Windows 2000 Standard Edition

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:

  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 query words: 2.00 2.01 3.50 4.00

Keywords: kbprogramming KB104960