VariantClear and VariantInit functions __ functions

Source: Internet
Author: User

What do two functions of the variantclear and VariantInit functions do? Recently, I have to seriously study the role of the program.

1.VariantClear () function

Clears the contents of a variant and sets the variant to VT_EMPTY.

How to do clears the contents of a variant (empty the contents of the variable). This is achieved by invoking the free space of the corresponding variable type. And he not only freed up space, but also initially changed the variables. The Simple English explanation is not translated.

Comments

VariantClear is used to clear the contents of initialized variants. Use VariantClear before a Variant variable goes out of scope (i.e. to release the contents of local variants before Leavin G A subroutine or function).

VariantClear sets the content of Vardest to Vt_empty. In addition, if Vardest had a reference to a bstring or Safe Array, and VariantClear calls Strfree to release the MEM Ory with the bstring or SafeArrayDestroy to destroy the contained Safe Array. If Vardest had a reference to a object, VariantClear calls the "object" method.

You don ' t need to call variantclear for variants, that contain values, are not dynamically allocated. For example, you don ' t need to call this subroutine to clear a Variant containing a VT_I4 (an integer) or a vt_r4 (real) v Alue. Note, however, which failure to call VariantClear on variants, contain dynamically allocated values may, Memor Y leaks, because the bstring or Safe Array referenced by the variant may never.

2.VariantInit function

Initializes a variant to Vt_empty

His role is very simple, that is, initially into VT_EMPTY. In fact, this variantclear () has been done, if you call it, you can not VariantInit ().

3. Tell me about the problems I've been having.

There has been a memory access violation error, I use the method of annotation, finally to locate a line of code.

SafeArrayDestroy (SA);

VariantClear (&SA);

Just call VariantClear (&SA), and then you have to delete it, it's okay. Check the function description to understand that the original is because the SA space released two times ah. and VariantClear (&SA); This can free space according to type, feel better, and finally put SafeArrayDestroy (SA); Solve the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.