Solved

Converting a COleVariant

Posted on 2001-09-08
3
629 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

821 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