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

Converting VARIANT.bVal to a char* ?

34 views
Skip to first unread message

Stan McDaniel

unread,
May 22, 1998, 3:00:00 AM5/22/98
to

Am I missing something or is there an easy way to convert
a VARIANT.bVal to a char* or string compare a VARIANT.bVal
and a char*. Thanks.

--Stan

Gil Sudai

unread,
May 23, 1998, 3:00:00 AM5/23/98
to

maybe this will help:
void VarToCStr(CString & str, const COleVariant & olevar)
{
if (VT_BSTR == olevar.vt)
str = (LPCTSTR)olevar.bstrVal;
else
str.Empty();
}

Thomas Stuefe

unread,
May 23, 1998, 3:00:00 AM5/23/98
to

Gil Sudai schrieb in Nachricht <6k69oc$qsu$1...@news.ibm.net.il>...

It's somewhat more tricky. If the VARIANT is an VT_BSTR, the string may be
stored either as UNICODE or as ANSI string - depending from where you get
the string. Therefore you have something like this:

if is UNICODE
str = (LPCTSTR) (var.bstrVal)
else
str = (char*) var.pbVal

The only way I found to check if it's a UNICODE or single byte string is to
scan the string itself and determine the string format from the typical
UNICODE byte pattern xx 00 xx 00 - not a very clean way, and
IF SOMEONE HAS A BETTER SOLUTION; I WOULD APPRECIATE TO HEAR FROM IT!

for more information see "multibyte string survival guide" from the msdn

0 new messages