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

how to convert a CString into a VARIANT ??

381 views
Skip to first unread message

Frédéric VIALLET

unread,
Dec 19, 2000, 12:02:25 PM12/19/00
to
hi,

use : VC++ 6

how to do to convert a CString into a VARIANT ?
VARIANT v;
v.bstrVal="toto";

??

Thanks for help on the subject

Fred


Ali

unread,
Dec 19, 2000, 12:13:25 PM12/19/00
to
I have never used it but just from looking at it
bstrVal is a BSTR, its a char *. You can't just assign a string to it.

something along this line.... or just do a new v.bstrVal = new char[100];
and then copy into it.

VARIANT v;
char *Temp[100];
strcpy(Temp,"toto");
v.bstrVal = Temp;

Ali

"Frédéric VIALLET" <fvia...@com1.fr> wrote in message
news:91o4be$pl$1...@s1.read.news.oleane.net...

Dave Smith

unread,
Dec 19, 2000, 12:33:04 PM12/19/00
to
Fred,

Why not use the MFC class COleVariant? It has a constructor which takes a
CSting as a parameter.

Dave Smith

"Frédéric VIALLET" <fvia...@com1.fr> wrote in message
news:91o4be$pl$1...@s1.read.news.oleane.net...

Frank Ostrowski

unread,
Dec 19, 2000, 5:27:10 PM12/19/00
to

Variant BSTR are not pointers to char. But pointers to specially
allocated Unicode Strings.
VARIANT v;
v.vt = VT_BSTR;
v.bstrVal = SysAllocString(L"toto");

Easier is to use the MFC supplied Variant wrapper, even including
automatic conversions from CString to and from Variant, and double,
int, DATE...

Frank

Paul

unread,
Dec 19, 2000, 8:18:49 PM12/19/00
to
_variant_t, COleVariant, CComVariant .... this is getting silly......

Dave Smith <Brind...@Compuserve.com> wrote in message
news:es1IBKeaAHA.1564@tkmsftngp03...

Julie

unread,
Dec 20, 2000, 8:26:21 AM12/20/00
to
==================================

CString S;
CComBSTR bstr(S.AllocSysString());
_variant_t var(bstr);

==================================

"Frédéric VIALLET" <fvia...@com1.fr> wrote in message
news:91o4be$pl$1...@s1.read.news.oleane.net...

Julie

unread,
Dec 20, 2000, 9:03:32 AM12/20/00
to
Actualy, The easiest way is -

===================================

USES_CONVERSION;
CString s;
_variant_t var( A2W(s));

===================================

Tell me its not short....... :o)

"Frédéric VIALLET" <fvia...@com1.fr> wrote in message
news:91o4be$pl$1...@s1.read.news.oleane.net...

Frédéric VIALLET

unread,
Dec 20, 2000, 9:35:14 AM12/20/00
to
thanks Julie ;)

all works fine.

Regards,

Fred

"Julie" <michal...@contop.com> a écrit dans le message news:
uuZnp3oaAHA.2184@tkmsftngp05...

0 new messages