short vartoi(const _variant_t& var)
{
short value = 0;
switch (var.vt)
{
case VT_BOOL:
value = var.boolVal;
break;
case VT_UI1:
case VT_I1:
value = var.bVal;
break;
case VT_I2:
case VT_UI2:
value = var.iVal;
break;
case VT_NULL:
case VT_EMPTY:
value = 0;
break;
default:
TRACE(_T("Warning: 未处理的 _variant_t 类型值; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
}
return value;
}
long vartol(const _variant_t& var)
{
long value = 0;
switch (var.vt)
{
case VT_BOOL:
value = var.boolVal;
break;
case VT_UI1:
case VT_I1:
value = var.bVal;
break;
case VT_UI2:
case VT_I2:
value = var.iVal;
break;
case VT_I4:
case VT_UI4:
value = var.lVal;
break;
case VT_INT:
value = var.intVal;
break;
case VT_R4:
value = (long)(var.fltVal + 0.5);
break;
case VT_R8:
value = (long)(var.dblVal + 0.5);
break;
case VT_DECIMAL:
value = (long)var;
break;
case VT_CY:
value = (long)var;
break;
case VT_BSTR://字符串
case VT_LPSTR://字符串
case VT_LPWSTR://字符串
value = atol((LPCTSTR)(_bstr_t)var);
break;
case VT_NULL:
case VT_EMPTY:
value = 0;
break;
default:
TRACE(_T("Warning: 未处理的 _variant_t 类型值; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
}
return value;
}
double vartof(const _variant_t& var)
{
double value = 0;
switch (var.vt)
{
case VT_R4:
value = var.fltVal;
break;
case VT_R8:
value = var.dblVal;
break;
case VT_DECIMAL:
value = (double)var;
break;
case VT_CY:
value = (double)var;
break;
case VT_BOOL:
value = var.boolVal;
break;
case VT_UI1:
case VT_I1:
value = var.bVal;
break;
case VT_UI2:
case VT_I2:
value = var.iVal;
break;
case VT_UI4:
case VT_I4:
value = var.lVal;
break;
case VT_INT:
value = var.intVal;
break;
case VT_BSTR://字符串
case VT_LPSTR://字符串
case VT_LPWSTR://字符串
value = atof((LPCTSTR)(_bstr_t)var);
break;
case VT_NULL:
case VT_EMPTY:
value = 0;
break;
default:
value = 0;
TRACE(_T("Warning: 未处理的 _variant_t 类型值; 文件: %s; 行: %d\n"), __FILE__, __LINE__);
}
return value;
}
//我转载别人的