I need to perform a safe conversion between a _variant_t and a type such as long\bool_bstr_t etc.
There are many options to do this, but I'm getting lost in the (poor) documentation. For example for conversion to long: Option 1: Check if the variant type is long (==VT_I4), and if so perform a static cast. Option 2: Use an extractor, which I don't fully understand. The MSDN says that if the VARIANT is not already the proper type, VariantChangeType is used to attempt a conversion. However VariantChangeType returns an error code if it fails. Where do I get this error code? The return type should be of the type we're extracting to shouldn't it?
I'd appreciate the most safe solution and an explanation of the various options.