Solved

Converting a COleVariant

Posted on 2001-09-08
3
628 Views
Last Modified: 2008-03-06
In C++, is there a nice, easy, guarunteed way to convert a COleVariant (or VARIANT) string to a CString?
0
Comment
Question by:Ahriman
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 6467717
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
 
LVL 6

Accepted Solution

by:
Triskelion earned 100 total points
ID: 6467790
Got it.
Cast the .bstrVal to a LPCWSTR.

     COleVariant varX("#156Z");
     CString        strAsdf;
     strAsdf=(LPCWSTR)varX.bstrVal;
     AfxMessageBox(strAsdf);
0
 

Author Comment

by:Ahriman
ID: 6468481
Thanks - nice one! Looks as though this should also be unicode-compliant (if ever needed). Thanks again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now