How to convert VARIANT to integer
See the question and my original answer on StackOverflowIf you don't really know the type of what the variant holds (in your example, it seems to be a string represented as a VT_BSTR), the best and safest way is to call the Windows API VariantChangeType (or VariantChangeTypeEx is localization is an issue); here is an example (not boost-specific):
VARIANT vIn;
VariantInit(&vIn);
vIn.vt = VT_BSTR;
vIn.bstrVal = ::SysAllocString(L"12345678");
VARIANT vOut;
VariantInit(&vOut);
// convert the input variant into a 32-bit integer
// this works also for other compatible types, not only BSTR
if (S_OK == VariantChangeType(&vOut, &vIn, 0, VT_I4))
{
// now, you can safely use the intVal member
printf("out int: %i\n", vOut.intVal);
}
VariantClear(&vOut);
VariantClear(&vIn);