Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

VariantChangeType() doesn't work well to convert VT_I8 to VT_DECIMAL and vice versa

已查看 24 次
跳至第一个未读帖子

Bae, Hyun-jik

未读,
2002年9月22日 21:58:202002/9/22
收件人
VariantChangeType() doesn't work well to convert VT_I8 to VT_DECIMAL and
vice versa. I tested it with _variant_t class(This class is included in
VS.NET) and I tracked the source code lines and found VariantChangeType()
returns error.
However, not every machine commits this error. My computer has Windows XP
and it works well. However, Windows 2000 Server machine cannot. I guess
VariantChangeType() is related to Windows OLE core so if OS doesn't support
it, there's no way but to wait for next upcoming Windows Update.
For workaround, recently, I made another function converting to VT_DECIMAL
to VT_I8 and vice versa, isolating VariantChangeType() for converting
between them. Of course, it is more generic way to find how
VariantChangeType() can convert them well.

Is there no way but to make another workaround function like below? The
other solutions? Please reply. Thanks in advance.

Bae, Hyun-jik

-----------------------

ADOVariant ToVariant(LONGLONG x)
{
DECIMAL d;
d.scale=0;
d.sign=0;
d.Hi32=0;
if(x<0)
{
d.sign=DECIMAL_NEG;
d.Lo64=-x;
}
else
{
d.sign=0;
d.Lo64=x;
}
_variant_t l=d;
return l;
}

ADOVariant ToVariant(ULONGLONG x)
{
DECIMAL d;
d.scale=0;
d.sign=0;
d.Hi32=0;
d.Lo64=x;
_variant_t l=d;
return l;
}

LONGLONG ToLongLong(const ADOVariant &r)
{
DECIMAL d=r;
if(d.scale!=0)
_com_issue_error(DISP_E_OVERFLOW);
if(d.sign!=0)
return -LONGLONG(d.Lo64);
else
return d.Lo64;
}

ULONGLONG ToULongLong(const ADOVariant &r)
{
DECIMAL d=r;
if(d.scale!=0)
_com_issue_error(DISP_E_OVERFLOW);
if(d.sign!=0)
return -LONGLONG(d.Lo64);
else
return d.Lo64;
}

0 个新帖子