How to Change Type of a VARIANT
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 th开发者_如何学Pythone 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.
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.
精彩评论