在将VC ++ 6.0开发的代码迁移到Visual Studio 2008时,我收到了以下警告
警告C4244:'=':从'long'转换为'VARTYPE',可能会丢失数据
代码段:
STDMETHODIMP CTextFileParser::FormatString(long lTargetType, BSTR szFormat, BSTR szInput, VARIANT *value) // Has Definition of lTargetType
CComVariant vErg(szSource.c_str()); // Definition of vErg
vErg.vt = lTargetType; // C4244
警告C4244:'参数':从'long'转换为'VARTYPE',可能会丢失数据
代码段:
STDMETHODIMP CField::get_ContentWithType(long lType, VARIANT *pVal) // Has Definition of lType
{
HRESULT hRC;
CComVariant oNewValue(m_content); // Definition of oNewValue
hRC = oNewValue.ChangeType(lType, NULL); // C4244
if (SUCCEEDED(hRC)) oNewValue.Detach(pVal);
return hRC;
}
我无法修复此警告?..
答案 0 :(得分:1)
VARTYPE是16位整数类型:
WTYPES.H:typedef unsigned short VARTYPE;
你会想要static_cast<VARTYPE>()
。