Click to See Complete Forum and Search --> : BSTR to CString


Laurent Bernard
May 18th, 1999, 11:00 AM
When i try to read a BSTR in a COleVariant with

CString Cs;
Cs.Format("%s", Variant.bstrVal);

my Cs contains just the first character of the string. Could you explain me why and what is the good methode to do this !

---------------------------------------------
Laurent BERNARD
Ingénieur Développement - Logiciel Visilog

NOESIS
6, rue de la réunion
91940 Les Ulis

E-mail : lb@noesis.fr

Tél.: 01 64 86 78 50 poste 290
------------------------------------------------

chiuyan
May 18th, 1999, 11:45 AM
CString Cs = Variant.bstVal;

--michael

May 18th, 1999, 11:48 AM
1. use _bstr_t.
It has a char* operator.
So, u can use it like this :
_bstr_t my_bstr;
CString s1 = (char*)my_bstr;

Or
2. You can try this:
Variant.vt = VT_BSTR;
CString s2 = V_BSTRT(&Variant);