tags:

views:

59

answers:

1

Hi,

I'm having a VARIANT with its type set to VT_R8. Subsequently I need to change its type to VT_BSTR.

I would like know whether there is a way of resetting a VARIANT status.

Thus, I noticed that every time I set value to the VARIANT (in my case, its double) , VARIANT itself set its bstrVal member to a bad pointer, even though I set bstrVal member to NULL at the initialization of VARIANT. Why such thing is happening ?

Is it safe to use a VARIANT as structure where both dbVal and bstrVal member are set ?

Please clarify, thank you.

+1  A: 

VARIANT is a structure with a union inside. Depending on the type (VARIANT::vt) you interpret that union in different ways. If you set use VARIANT to store a double you only use the "double" field, not any others. If you want to reuse the variant to store BSTRs change the type accordningly - in your case simple change the "type" value and set "BSTR" value to null.

sharptooth