Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

24 views
Skip to first unread message

Bae, Hyun-jik

unread,
Sep 22, 2002, 9:58:20 PM9/22/02
to
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 new messages