Converting a COleVariant

In C++, is there a nice, easy, guarunteed way to convert a COleVariant (or VARIANT) string to a CString?
AhrimanAsked:
Who is Participating?
 
TriskelionCommented:
Got it.
Cast the .bstrVal to a LPCWSTR.

     COleVariant varX("#156Z");
     CString        strAsdf;
     strAsdf=(LPCWSTR)varX.bstrVal;
     AfxMessageBox(strAsdf);
0
 
TriskelionCommented:
It looks as if the W2A() function does the trick.
I'm trying it, but am getting an error.

Check this example:
http://www.trustsoft.com/eng/varient.htm
0
 
AhrimanAuthor Commented:
Thanks - nice one! Looks as though this should also be unicode-compliant (if ever needed). Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.